TOTP Code Generator

The current 2FA code for a Base32 secret or otpauth URI, and new secrets with a QR code.

About TOTP Code Generator

A TOTP generator that shows the current and next one-time code for a Base32 secret or otpauth URI, and makes new secrets with a QR code.

How to use

  1. Paste a Base32 secret, the string a service shows under its setup QR code. Pasting a whole otpauth:// URI works too: it is unpacked into the fields.
  2. The current code appears with the seconds left before it changes, and the next code beside it.
  3. Leave digits, period and algorithm alone unless the service states other values. Almost all use 6 digits, 30 seconds and SHA-1.
  4. To set up a new key, press Random secret, fill in the issuer and account, and scan the QR code with an authenticator app or copy the otpauth URI.

What it does

  • The code follows RFC 6238: the number of whole periods since 1 January 1970 UTC is signed with HMAC using the secret, and the result is cut down to 6 or 8 decimal digits as RFC 4226 describes. HMAC with SHA-1, SHA-256 or SHA-512 runs in WebCrypto.
  • The secret is read as Base32. Lower case, spaces, hyphens and = padding are accepted.
  • Random secret draws 160 bits from the browser's secure random source, which gives 32 Base32 characters.
  • The otpauth URI has the form otpauth://totp/Issuer:account?secret=…&issuer=…&algorithm=SHA1&digits=6&period=30, the key URI format that authenticator apps read. The QR code is drawn on this page from that URI and can be downloaded as a PNG.

What it does not do:

  • It handles time-based keys only. Counter-based otpauth://hotp keys and proprietary schemes such as Steam Guard are not supported.
  • It does not read a QR code image. Decode the image with a QR reader first and paste the URI.
  • It does not keep secrets: reloading the page clears everything.
  • It uses your device's clock. If the clock is off by more than about one period, the codes will be rejected.

Example

secret     GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ   (ASCII 12345678901234567890)
time       1970-01-01 00:00:59 UTC  → counter 1
algorithm  SHA-1, period 30 s

8 digits → 94287082   (RFC 6238 test vector)
6 digits → 287082

Privacy

Codes, secrets and the QR code are computed in JavaScript on this page. The secret is not uploaded, no request is made, and nothing is stored.

Frequently asked questions

How does a TOTP code work?
The service and your authenticator share a secret. Both divide the current Unix time by the period, usually 30 seconds, sign that counter with HMAC using the secret, and reduce the result to six digits. Because both sides compute the same number from the same time, the code proves you hold the secret without sending it.
Is it safe to enter a 2FA secret into a website?
The secret is the second factor: anyone who has it can produce your codes for good. This page computes codes locally and sends nothing, but a browser extension or a shared computer can still see what you type. Use it for test accounts and development, and keep the secrets of real accounts in an authenticator app.
Why is my TOTP code not accepted?
The usual cause is a clock that is off by more than 30 seconds, so set the device time automatically. Otherwise check that the secret was copied in full and that digits, period and algorithm match what the service expects; a few services use 8 digits or SHA-256.
What is an otpauth URI?
It is the text inside a 2FA setup QR code, for example otpauth://totp/Example:alice@example.com?secret=JBSWY3DPEHPK3PXP&issuer=Example. It carries the secret, the account label and optionally the algorithm, digits and period, so an authenticator app can be configured with one scan.