OTP Code Generator

Generates a live TOTP code from a Base32 secret — the same six digits your authenticator app shows — refreshing every thirty seconds. It implements RFC 6238 properly: HMAC-SHA1 over the time counter, truncated to six digits.

Live demo · real result from this tool
Digits
Period
Current code800881
Seconds left in this window
4
Previous code
324918
Next code
959706
Time step
59769641

Codes are computed in this tab with HMAC (RFC 6238). Change any field to refresh. A wrong code is usually a clock that is more than 30 seconds out.

Processed on your device — nothing is uploaded.

How to use OTP Code Generator

  1. Paste the Base32 secret from your provider’s setup screen — the text shown under the QR code.
  2. The current code appears, with a countdown to the next one.
  3. Enter it before the countdown runs out; if it is close, wait for the next.
  4. Standard parameters: 30-second period, 6 digits, HMAC-SHA1 — what almost every service uses.
  5. The secret is Base32, not Base64: only A–Z and 2–7, with optional = padding.
  6. Computed in your browser with the Web Crypto API; nothing is transmitted.

How a six-digit code is derived from a shared secret

The server and your device share a secret once, at setup, in that QR code. From then on nothing is transmitted. Both sides take the current Unix time, divide by thirty to get a counter, compute HMAC-SHA1 of that counter with the shared secret, and take a four-byte window from the result using the last nibble as an offset — dynamic truncation. The number modulo one million gives six digits. Because both sides compute independently from the clock, the code works offline, on a plane, with the phone in flight mode.

Why the code is not really a second factor here

TOTP is meant to be something you have, held on a separate device. A code generated on the same machine where you type the password, from a secret stored in the same password manager, is closer to a second copy of the same factor: one compromise takes both. That trade is sometimes worth making, and it is a real improvement over no second factor at all, but it is worth knowing what you have chosen. Use this tool for testing an integration, recovering access, or checking that a secret was transcribed correctly — not as your day-to-day authenticator for anything that matters.

Clock drift is the usual failure

If your device’s clock is more than about thirty seconds out, every code you generate will be rejected, because both sides derive the counter from the time. Servers normally accept the previous and next window to allow for this, giving roughly ninety seconds of tolerance. When an authenticator suddenly stops working, the clock is the first thing to check — enabling automatic network time usually fixes it outright.

Handling the secret

The secret is Base32 — A to Z and 2 to 7 — because it has to survive being typed by hand when a QR code will not scan. Spaces and lowercase are accepted and normalised. That secret is the whole credential: anyone who has it can generate valid codes forever. Store it where you would store a password, save the recovery codes the service offered at setup, and remember that a secret pasted into any web page should be regarded as worth rotating.

Frequently asked questions

What is TOTP?
Time-based One-Time Password (RFC 6238) derives a 6-digit code from a shared secret and the current time, changing every 30 seconds.
Will these codes match my authenticator?
Yes — for the same Base32 secret the codes match Google Authenticator, Authy and similar apps.
Is my secret sent anywhere?
No — codes are computed locally with HMAC-SHA1 and the secret never leaves your browser.
Why is my code being rejected?
Nearly always clock drift — TOTP derives the code from the current time, so a device clock more than half a minute out produces codes for the wrong window. Turn on automatic time sync. Otherwise check the secret was copied completely, and that the service does not use non-standard settings such as eight digits or a sixty-second period.
Is this as secure as an authenticator app?
The mathematics is identical, but the security model is not: an app on a separate device keeps the secret away from the machine you log in on. Generating codes in the same browser collapses two factors into one point of compromise. Use this for testing and recovery, and a phone app for accounts that matter.
What is the difference between TOTP and HOTP?
TOTP counts time windows, so codes expire every thirty seconds. HOTP counts events, so a code stays valid until used and the two sides can drift out of step if codes are generated without being submitted. TOTP is what almost every service uses today.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Guides

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close