TOTP Code Generator
2FA Codes And otpauth QR
Test two-factor codes without a phone. Paste or generate a Base32 secret and watch the live RFC 6238 code count down, check codes for any moment, and build or read otpauth:// links with a QR code. Computed with your browser's WebCrypto. 100% client-side. Zero data stored.
TOTP Code Generator Tool
The secret stays in this tab
- A random secret comes from
crypto.getRandomValues. Every code is an HMAC computed in your browser by the open-source otpauth library (MIT), which supports TOTP and HOTP with SHA-1, SHA-256 and SHA-512.Math.randomis never used. - The secret is never stored (no cookies, no localStorage, no URL) and never sent: this page makes no network request with it. The QR code is drawn in your browser.
- Anyone who can see the secret or the QR code can generate your codes. Use this for development, testing and learning; for a real account, scan the code your service shows you into an authenticator app instead.
Secret and settings
Current code
Next code: --- ---
otpauth link and QR code
Scan with an authenticator app
Some authenticator apps ignore the algorithm, digits and period values and always use SHA-1, 6 digits and 30 seconds. Test your app before using other settings.
Codes for a chosen time
| Period | Counter | Starts (Unix) | Code |
|---|
Check a code
Read an otpauth:// link
Common Use Cases
Test a 2FA login flow
Enroll a test account with a secret you control, then read the current code to walk through your own sign-in and recovery screens without a phone.
Provision an authenticator
Turn a Base32 secret from a server, a vault or a ticket into an otpauth link and a QR code that an authenticator app can scan.
Debug "invalid code" errors
See the codes for the periods before and after a moment, and which one a typed code matches, to tell clock drift from a wrong algorithm or digit count.
Check your own implementation
Compare your server's TOTP code with a second implementation, and use the RFC 6238 test secret to confirm a library matches the published values.
Read an old enrollment link
Paste an otpauth link from a screenshot or an export to see its issuer, account, algorithm, digits and period before you move it to a new app.
Learn how TOTP works
Change one setting at a time and watch the counter, the period start and the code change, with the same numbers the RFCs publish.
TOTP Reference
| Part | Example | Meaning |
|---|---|---|
| otpauth://totp/ | otpauth://totp/ | The scheme and type. totp is time-based; hotp is counter-based. |
| label | Example:alice | Issuer and account name joined by a colon, percent-encoded. It is what the app shows. |
| secret | JBSWY3DPEHPK3PXP | Required. The shared key in Base32 (letters A-Z and digits 2-7), without padding. |
| issuer | Example | Recommended. The service name; it should match the label prefix. |
| algorithm | SHA1 | SHA1 (default), SHA256 or SHA512. Many apps support only SHA1. |
| digits | 6 | Code length: 6 (default), 7 or 8. Many apps support only 6. |
| period | 30 | Seconds each code lasts. 30 is the default and the value apps expect. |
How a code is made
The counter is the Unix time divided by the period, rounded down. The code is the HMAC of that counter under the secret, cut down to a few digits (RFC 4226 section 5.3). Both sides compute it independently, so nothing needs to be sent.
Secret length
RFC 4226 requires at least 128 bits and recommends 160 (20 bytes, 32 Base32 characters). Shorter secrets still produce codes, and some services issue 80-bit ones, but they are easier to guess. The tool tells you the size of what you paste.
Clock drift
A code depends on the clock of the phone and the server. Servers usually accept the periods just before and after the current one. If a code is rejected by one period only, check the device time first.
RFC 6238 test values
With the test secret, SHA-1 and 8 digits, Unix time 59 gives 94287082, 1111111109 gives 07081804 and 1234567890 gives 89005924. Load the test secret above to see them. The RFC uses a longer key for SHA-256 and SHA-512.
What this tool is not
It is not an authenticator app: it keeps no accounts, does not back anything up and forgets everything when you close the tab. It also cannot read a QR code; paste the otpauth link instead.
Counter-based codes
HOTP (RFC 4226) uses an event counter instead of the time. The time-based codes here are the same algorithm with the counter taken from the clock. An hotp link can be read, but only time-based codes are shown.
Frequently Asked Questions
A time-based one-time password is the short number an authenticator app shows and replaces every 30 seconds. It is defined in RFC 6238: the service and your app share a secret, and each computes a code from that secret and the current time, so a matching code proves you hold the secret without it being sent.
The page never sends, stores or logs the secret: the codes are computed in your browser with the open-source otpauth library and the secret is gone when you close the tab. Even so, a secret on screen can be seen, copied from the clipboard or captured by a browser extension, so we advise against pasting the secret of an account you care about. Use a test secret, or an authenticator app, for real accounts.
From crypto.getRandomValues, the browser's cryptographically secure random number generator, then written in Base32. Math.random is never used. The default is 20 random bytes (160 bits, 32 Base32 characters), the size RFC 4226 recommends.
Check four things: the secret was typed exactly, the algorithm, digits and period match what the app was given, the clock of this computer and the phone are both correct, and the app did not ignore a non-default setting (some apps only do SHA-1, 6 digits, 30 seconds). Use the "Codes for a chosen time" table to see whether the app's code belongs to the previous or next period, which points to clock drift.
Base32 (RFC 4648) writes binary data with the letters A to Z and the digits 2 to 7, which are easy to read aloud and type. This tool ignores spaces, hyphens, lowercase letters and trailing equals signs in a pasted secret, and tells you which character is wrong if it finds a 0, 1, 8 or 9.
Use SHA-1, 6 digits and 30 seconds unless you control both ends. They are the defaults in the standards and the only values every authenticator app is sure to honor. SHA-1 is weak as a plain hash, but HMAC-SHA-1 is not broken by the known attacks, and TOTP does not rely on collision resistance.
Fill in the secret, an issuer and an account name, then scan the QR code beside the otpauth link with the app's add-account screen, or copy the link into an app that accepts one. The QR code is drawn in your browser and holds the secret, so treat a screenshot of it like the secret itself.
It cannot scan a QR image: decode it with the QR Code Scanner on this site and paste the otpauth link here. A counter-based hotp link loads its secret and settings, but the code on screen is always time-based, because the tool does not keep a counter.
No. The secret stays in the page's memory: it is not saved to cookies or local storage, not put in the address, and not sent to any server. Reloading or closing the tab clears it.
Why We Built This TOTP Code Generator
Anyone who builds a login system ends up needing a one-time-code generator that is not their phone: to test an enrollment screen, to reproduce a bug report that says "the code is always rejected", or to hand a QA team a secret and a QR code. The usual answer is a random website that asks you to paste the secret, and that is a poor place for a secret to land.
This tool computes every code in your browser with the open-source otpauth library, takes its random secrets from the same secure generator, and says on the page which function produced each value. Nothing is stored and nothing is sent, so the worst case is the same as typing the secret into a local script. It follows RFC 4226 and RFC 6238 and reproduces their published test values, and it builds and reads the otpauth links that authenticator apps use.
The TOTP Code Generator is part of RJL.io's collection of free developer tools. For the rest of your security toolbox, try the Password Generator, the Hash Generator, the QR Code Generator and the JWT Decoder, or the Key and Token Generator for API keys and key pairs.