Free · runs in your browser

TOTP Code Generator

TOTP Code Generator. Paste your secret key to watch a live, rotating TOTP code update in real time. Once the image is ready, generate a two factor qr code and save a backup of the secret, since losing the phone could lock you out of the account.

Your values

The setup key from your 2FA screen. Spaces and dashes are ignored. An otpauth:// URI uses its own secret, algorithm, digits and period. Everything runs in your browser.

Most setup screens show base32 (A-Z, 2-7). Hardware token seeds are often hex.

SHA-1 is the default for Google Authenticator, Microsoft Authenticator and Authy.

Usually 30 seconds; some systems use 60.

Lists the codes for time steps before and after now, to spot a clock that runs fast or slow.

Result

TOTP Code
—
Time Until Refresh
—
Time Step Counter
—
Secret in Other Format
—
  • No account, no logging
  • Open formulas explained below
  • Works offline once loaded

Need the six-digit number your phone shows, without hunting for the phone? This TOTP code generator turns your secret key into live TOTP tokens that match Google Authenticator and Authy, refreshing on its own so you can copy a valid code and finish in seconds.

TOTP code generator basics: two-factor authentication codes

A time-based one-time password is a short, single-use number that proves you hold a key without ever sending it. Under RFC 6238, the IETF standard behind it, your device and the server share a key, feed it through HMAC together with the current time, and keep a truncated slice of the result as a few digits. Every OTP is temporary and will expire within moments, so a stolen code is nearly worthless to an attacker. That extra step is why two-factor logins hold up even when a reused credential leaks.

The shared secret carries the entropy, while the clock supplies the changing input. An online one-time password generator such as this one does identical math inside your browser, so security rests on keeping that shared secret private.

How this 2FA code generator reads your base32 secret

Paste the base32 secret from the service's setup screen and the page does the rest. It counts how many whole intervals of one period have passed since the Unix epoch, using the current timestamp:

Formula card showing counter 59,374,485 producing the TOTP code 633493, with a bar showing 17 of 30 seconds already used
How one counter value becomes the 6-digit code 633493, and how far into its 30-second step 03:22:47 falls.

\(T = \lfloor t / 30 \rfloor\)

Each time step lasts 30 seconds, and both sides derive matching tokens for the same value of \(T\). Click the digits to copy the 2FA code to your clipboard, then paste it into the login form.

You can check the arithmetic by hand. At Unix time 1,700,000,000 the division gives \(T = 56{,}666{,}666\) with a remainder of 20, so the current code has 10 seconds left before \(T\) increases by one and everything changes. The published test vector goes further: the ASCII key 12345678901234567890 at Unix time 59 gives \(T = 1\) and the 8-digit code 94287082. If a generator cannot reproduce that number, its math is wrong, not your key.

To generate a code from start to finish:

  1. Copy the key from the screen where you enrolled the account.
  2. Paste it into the field above and choose the hash and the number of digits.
  3. Wait for the live code to appear, then compare it with your phone if you want a cross-check.
  4. Copy the code and submit it before the ring empties.

Scan a QR code or paste your secret key

If the service displays a QR code, upload a screenshot or scan it; otherwise choose manual entry and type the key printed beneath it. Both routes give you the same string, because a QR code is only a wrapper around it.

Read the 30-second countdown

The progress ring shows how long the current code lives. When it reaches zero a fresh code replaces it and the old one expires, so copy the digits before the timer resets. A 30-second window is the RFC default.

Extract the secret from an otpauth URI

Some services hand you an otpauth:// link rather than plain text. Copy the value after secret=; it is the base32 string this tool expects, and the issuer and account name in the URI are only labels. Leave them out if you like; they never change the code.

SHA-1, SHA-256 or SHA-512 for a TOTP authenticator

Pick the algorithm your service uses. If the algorithm differs on the two sides, each produces a different token every time, even with the same key and clock. Match the number of digits too.

Bar chart of SHA-1, SHA-256 and SHA-512 digest sizes with the different 6-digit code each gives at the same moment
The same secret and instant give a different code under each hash algorithm.
SHA-1, SHA-256 or SHA-512 for a TOTP authenticator
Hash or lengthTypical choiceWhen it fits
SHA-1DefaultNearly every consumer app
SHA-256StricterYou control the client and server
SHA-512StrongestRarely supported, so check first
6 digitsCommonBest balance of ease and strength
8 digitsOptionalOnly if the service asks for it

6 digits or 8 digits

Stay with six unless the service says otherwise, since the extra length rarely repays the typing effort on a phone keypad. An 8-digit OTP adds a little entropy but few consumer apps accept it, so match the digit length your account expects. Changing the length does not change the underlying number, only how many of its trailing digits are shown.

Checking a staging account with this TOTP code generator

A QA engineer enrolling a staging account has one question: will the code the build server derives be accepted at login? Her service shows the base32 key UVG4UGBFGC5R23ITFTPNMI33F3MR4P3S and says SHA-1 with 6 digits, so she pastes it into this TOTP code generator, leaves those defaults alone and notes the time.

Timeline of four consecutive 30-second windows and the 6-digit code each produces, centred on the current window
The code changes at each 30-second boundary; a one-step grace window accepts the neighbours of the current code.

At Unix time 1,794,484,321 the division gives \(T = 59{,}816{,}144\) with a remainder of 1, so the window just opened and 29 seconds remain. The tool shows 932874. She cross-checks the neighbouring windows by hand: the previous one gives 978623 and the next 384158, and RFC 6238 advises servers to tolerate exactly one step on either side. Her phone's authenticator shows 932874 as well, so the algorithm and key agree.

Checking a staging account with this TOTP code generator
ChangeCode shownAccepted?
Nothing (baseline)932874Yes
Hash switched to SHA-256720872No
Test runner clock 47 seconds slow549516No

The sensitivity rerun is what she cares about. Switching the hash to SHA-256 changes the OTP completely, which is the quickest way to spot a settings mismatch. A clock that runs 47 seconds slow lands two steps back, outside the one-step grace, so the login fails even though the key is right. The number to watch is the clock offset, not the key: anything beyond 30 seconds is a failure, and a drift of 31 to 59 seconds can pass or fail depending on where in the window the request lands.

That edge case is where this tool's answer should not be trusted alone. A matching code proves the key and settings, not the runner's clock. Her next action is concrete: sync the test runner with a network time source, rerun, and only then commit the key to the pipeline vault.

Authenticator apps and Google Authenticator compatibility

Every major authenticator app runs the same RFC 6238 math, which is why a code made here matches the one on your phone. You can store the same key in several of them:

  • Microsoft Authenticator imports a key by manual entry or camera.
  • 1Password and Bitwarden keep the key beside the saved entry.
  • Authy syncs the 2FA key across your devices.

Automating an OTP in end-to-end test automation

QA teams stall when a login flow demands a code from a physical phone. A generator removes that dependency: keep the key in your CI vault, derive the OTP at run time, and your e2e tests stay green. Debugging gets easier too, since you can compare your token with the one a failing run produced. Many teams wrap the logic in an API endpoint, though a library or REST API works just as well for testing.

Security tips for your secret

Treat the key like a password, never paste it into chat, and store backup codes offline so account recovery stays possible. Prefer a passkey where one is offered, since it resists phishing. If you ever suspect the key was exposed, remove the device from the account and enroll again so a new key replaces the old one.

Fixing a verification code that does not match

When a code from this generator is rejected, the cause is almost always clock skew: compare it with your phone, sync both clocks and let your service accept one step on either side. Phones usually sync automatically, but a laptop that has been asleep for days can drift by a minute or more, which is enough to miss the window. Then confirm the algorithm and digit length agree. This generator uses the Web Crypto engine in your browser and computes locally, so you can retest as often as you need while you debug.

Frequently Asked Questions

How does this tool compute the code?
It follows RFC 6238 (TOTP) exactly: your Base32 secret is decoded to bytes, combined with the current time divided into 30-second (or custom) intervals via HMAC (SHA1, SHA256, or SHA512, computed with the browser's native Web Crypto API), then truncated down to a 6- or 8-digit code the same way every authenticator app does. The algorithm was verified against the official RFC 6238 test vectors during development.
Why does the code sometimes look wrong or not match my app?
The most common cause is a clock mismatch -- TOTP codes are time-based, so if your device's clock has drifted, the computed code won't match. Also double-check the algorithm, digits, and period match what the service actually issued you; most use the defaults (SHA1, 6 digits, 30 seconds), but a few don't.
Is it safe to paste my 2FA secret into this tool?
The secret is used entirely in your browser to compute the code locally -- it is never transmitted, logged, or stored anywhere, and disappears the moment you reload the page. That said, treat any TOTP secret as sensitive: anyone with it can generate valid codes for your account, so only use this on a device you trust.
What is this tool useful for?
Verifying an authenticator-app setup without needing your phone in hand, debugging a TOTP integration you're building, or checking that a secret and its resulting codes are actually correct before rolling it out.
Why does the code change right as the ring empties?
That's expected -- the ring shows how much of the current 30-second (or custom-period) window is left. When it fully drains, the time counter increments and a brand new code is computed, exactly matching how your physical authenticator app behaves.

About the author

Vinitha Pu

Founder and designer

Vinitha Pu is a graphic designer based in Palakkad, Kerala, who builds free, privacy-friendly browser tools. She studied Textile and Apparel Design at Avinashilingam University and completed a C-Tech in Graphic Design at Image Creative Education in 2025. She designs, builds and maintains the password generators, strength checkers, hash tools and security calculators on PasswordHive.

  • Content author: Vinitha Pu
  • Fact checked by: Vinitha Pu. Each tool's output is checked against official test vectors or a reference implementation, and every strength and crack-time figure against the formula it uses, before it goes live.
  • Published Updated