About this tool
Time-based one-time passwords (TOTP) are the 6-digit codes in authenticator apps. The app and the server share a secret key; each computes an HMAC of the current 30-second time window, so they agree on the code without talking to each other. This tool generates those codes from any secret, shows a QR code that sets up an authenticator app, and checks codes, which is everything you need to build and test two-factor authentication.
Secrets stay in this page: nothing is sent or stored, and the secret field is cleared when you leave.
How to use it
- Testing your own 2FA: paste the secret your app shows during setup (the text under the QR code) and compare codes with your server.
- Building 2FA: click New for a random 160-bit secret, scan the QR code with your phone, and use Check a code to test verification.
- Debugging “invalid code”: if codes match here but not on the server, the server’s clock is probably wrong; TOTP needs clocks within about 30 seconds.
How TOTP works (RFC 6238)
counter = floor(unix_time / 30)
hmac = HMAC-SHA1(secret, counter as 8 bytes)
offset = last 4 bits of hmac
code = (31 bits of hmac starting at offset) mod 10^6
Implementing 2FA well
- Generate secrets on the server with a secure random generator (at least 160 bits) and store them encrypted.
- Accept the current code and one step either side to allow for clock drift, and reject a code that has already been used.
- Rate-limit attempts: a 6-digit code has only a million possibilities.
- Give users recovery codes when they enable 2FA.
FAQ
What is a TOTP code?
A one-time password computed from a shared secret and the current time, usually 6 digits that change every 30 seconds, as defined in RFC 6238.
Why don’t my codes match my authenticator app?
Check that the secret is identical, that the algorithm, digits and period match (most apps use SHA-1, 6 digits, 30 seconds), and that your device’s clock is set automatically.
Is it safe to paste my 2FA secret here?
The code is generated in your browser and the secret is never sent or saved. Still, a 2FA secret is as sensitive as a password; only enter secrets for test accounts.
What is an otpauth URI?
A link in the form otpauth://totp/Issuer:account?secret=…&issuer=… that authenticator apps read from a QR code to set up an account.
TOTP vs HOTP?
TOTP codes change with time; HOTP codes change each time you press a button or use one, based on a counter.