This tool runs entirely on your device. Your files and the text you enter are processed by your browser and are never sent to a server.
2FA Code Generator (TOTP)
This free 2FA code generator turns a Base32 secret, an otpauth:// URI or a setup QR code into the live 6 or 8 digit TOTP code an authenticator app would show, with a countdown and the previous and next codes. Developers can generate a test secret with a QR code and verify codes. Everything is computed in your browser and nothing is uploaded.
Security first: read before pasting a secret
- Everything stays in your browser. Codes are computed locally; the secret is never uploaded, logged or put in the page URL.
- Nothing is savedunless you tick “Remember in this browser” (off by default). Closing the tab forgets it.
- Never paste secrets for important accounts on a shared or public computer. Use this for testing your own 2FA implementation and for checking backup secrets.
- Not a replacement for an authenticator app. Keep your real 2FA in Google Authenticator, Microsoft Authenticator, 1Password, Aegis or similar.
You can also drop or paste (Ctrl/Cmd+V) a screenshot of a setup QR code here. Decoding happens on your device.
Most services use 6 digits, 30 seconds and SHA1. Google Authenticator ignores other algorithms and periods on some versions, so test non-default settings with your target app.
Current code
Enter or generate a secret to see the live code.
Checks the code against the current time step ±1 (the usual server tolerance for clock drift).
How to generate a 2FA code from a secret
- Add a secret. Paste a Base32 secret such as JBSWY3DPEHPK3PXP, paste a full otpauth://totp/ URI, upload or scan a setup QR code, or click Generate new secret to create a random 160-bit test secret.
- Match the settings. Choose 6 or 8 digits, a 30 or 60 second period and the SHA1, SHA256 or SHA512 algorithm. Settings are filled in automatically when you import an otpauth URI or QR code.
- Read or copy the code. The current code updates live with a countdown ring, alongside the previous and next codes. Click Copy code to paste it into a login form.
- Test your setup. Scan the generated QR code with an authenticator app and compare codes, or type a code into Verify to check it against the current time step plus or minus one.
How TOTP works
A time-based one-time password (TOTP, RFC 6238) is an HOTP code (RFC 4226) whose counter is the current time. Your server and the authenticator app share one secret when you scan the setup QR code; after that they never need to talk to each other.
- Counter:
T = floor(unix_time / period), so with a 30 second period the counter changes twice a minute. - HMAC:
HMAC-SHA1(secret, T)as an 8-byte big-endian number (or SHA256/SHA512). - Dynamic truncation: the low 4 bits of the last byte pick an offset; 31 bits are read from there.
- Code: that number
mod 10^digits, zero-padded to 6 or 8 digits.
Secrets are shown in Base32 (A–Z and 2–7) so people can type them. RFC 4226 requires at least 128 bits and recommends 160 bits, which is 32 Base32 characters. The generator here uses 20 random bytes from crypto.getRandomValues.
Testing your 2FA implementation
When you build two-factor login, check your server against the RFC 6238 reference values. Use the ASCII seed 12345678901234567890 for SHA1 (the RFC repeats it to 32 bytes for SHA256 and 64 bytes for SHA512), 8 digits and a 30 second period:
| Unix time (s) | SHA1 | SHA256 | SHA512 |
|---|---|---|---|
| 59 | 94287082 | 46119246 | 90693936 |
| 1111111109 | 07081804 | 68084774 | 25091201 |
| 1234567890 | 89005924 | 91819424 | 93441116 |
| 2000000000 | 69279037 | 90698825 | 38618901 |
- Accept the previous and next time step (a ±1 window) to tolerate small clock drift, but no more.
- Reject a code that has already been used in the same step, so it can't be replayed.
- Rate-limit attempts: a 6 digit code has only a million possibilities.
- Compare codes in constant time and store secrets encrypted at rest.
- Give users recovery codes before they leave the setup screen.
Codes not matching? Quick checklist
- Clock: TOTP depends on the time. A phone or PC that is 30 seconds off is a whole code off. Turn on automatic date and time.
- Settings: digits, period and algorithm must match on both sides. Import the original otpauth URI rather than typing the secret alone.
- Secret typos: Base32 has no 0, 1 or 8. An O typed as 0 or an I typed as 1 is the usual culprit. Spaces and lowercase are fine.
- App support: some authenticator apps ignore SHA256/SHA512 or non-30 second periods. Test with your target app before shipping.
Related tools
Frequently Asked Questions
Is it safe to paste my 2FA secret into this tool?↓
The codes are calculated in your browser with JavaScript; the secret is never uploaded, logged or added to the URL, and nothing is saved unless you tick Remember in this browser. Even so, a 2FA secret is as sensitive as a password: only use this tool on your own device, never on a shared or public computer, and prefer it for test accounts and checking backup secrets rather than important accounts.
How is a TOTP code calculated?↓
TOTP (RFC 6238) divides the current Unix time by the period, usually 30 seconds, to get a counter. It computes an HMAC of that counter with the shared secret (SHA1 by default), picks 4 bytes from the result using the last nibble as an offset (dynamic truncation, RFC 4226), and takes that number modulo 10^digits to get the 6 or 8 digit code.
Why doesn't my code match my authenticator app?↓
The most common causes are a wrong device clock, different settings (digits, period or algorithm), or a typo in the secret. Turn on automatic time on both devices, import the original otpauth URI so the settings match, and remember that Base32 never contains 0, 1 or 8. Some apps ignore SHA256, SHA512 or 60 second periods and silently fall back to the defaults.
Can this replace Google Authenticator or another authenticator app?↓
No. It is a developer and recovery tool. An authenticator app keeps secrets in protected storage on a device you carry, which is what makes 2FA a second factor. A web page you open on the same computer you log in from does not give you that protection.
What is an otpauth:// URI?↓
It is the text inside a 2FA setup QR code, in the Key URI Format, for example otpauth://totp/Example:alice@example.com?secret=JBSWY3DPEHPK3PXP&issuer=Example&algorithm=SHA1&digits=6&period=30. Pasting it here fills in the secret, issuer, label, digits, period and algorithm in one step.
Does it work with 8 digit codes and SHA256?↓
Yes. You can choose 6 or 8 digits, a 30 or 60 second period and SHA1, SHA256 or SHA512. The implementation reproduces the RFC 6238 test vectors, for example the SHA1 secret 12345678901234567890 at T = 59 seconds gives 94287082.
You might also need
All Generators →Password Generator
Strong random passwords.
QR Code Scanner & Reader
Read QR codes from an image or your camera.
QR Code Generator
Create QR codes for links and text.
Hash Generator
SHA, MD5, HMAC, bcrypt and file checksums.
Base64 Encoder/Decoder
Encode and decode Base64 text.
UUID Generator
UUID v4, v7 and ULID generator.
Last updated: