OTP / TOTP Generator

Crypto

Generate TOTP codes (RFC 6238) from a base32 secret for 2FA and MFA authentication. Drop-in codes matching Google Authenticator, Authy and other TOTP apps, computed locally in your browser.

30s remaining
Current OTP
30------

About OTP / TOTP Generator

An OTP is the rotating code in two-factor auth that refreshes every few dozen seconds, most commonly the time-based TOTP (RFC 6238).It works by computing an HMAC over a shared secret and the current time window. Then truncating to a 6-digit number, so the server and your authenticator app derive the same code without any network. This tool generates TOTP codes locally in your browser from the Base32 secret you provide, shows the remaining seconds, and supports custom digits and period. For example, providing a shared secret yields the current 6-digit TOTP code with seconds remaining, matching your Authenticator app. Validity depends on both clocks being close, so time skew is the most common deployment failure. If the generator and server differ by more than the allowed window, every code fails and it presents as always rejecting the code. Check clock synchronisation between the two sides before examining the key and algorithm parameters; reversing the order wastes time. The two working modes differ in what they count, which decides the right choice. One counts time steps so the code changes automatically and suits manual entry, while the other counts events so each use increments the counter and suits hardware-driven cases. The former is sensitive to time and the latter to call count, and mixing them desynchronises the two ends. The key representation and length must match what the other side expects, the most error-prone part of integration. One binary key has several textual forms and different length requirements, and if one side provides one form while the other parses another, the codes never agree. State the encoding and length when configuring a key rather than supplying only the characters. The acceptance window width is a trade-off with costs at both ends. Too narrow lets slight skew fail immediately and users retry, too wide enlarges the reuse space for a single code and weakens security. Set the width against the real clock synchronisation quality and keep both sides equal rather than tightening or loosening unilaterally. This code is a second factor whose value rests on being separate from the password. Storing it alongside the password or delivering both through one channel reduces two factors to one, and the one-time recovery codes should be kept offline since they are the only way in if the device is lost. Explain how to store them when enabling. Finally, it differs fundamentally from a message-based code and the two should not be conflated. A message code depends on the carrier network and carries interception and SIM-swap risk, whereas a locally generated code never crosses the network, making it safer but dependent on the device. That difference guides selection toward local generation where security matters.

How It Works Internally

A time-based code feeds the shared secret and the current time step into a hash function and truncates the result to fixed-length digits. Output therefore depends on exactly three things: the secret, the step size and the current time. Any mismatch fails continuously, and clock drift is the most insidious — a device more than one step behind never matches, which is why checking the clock comes first.

InputA Base32 secret with a 30-second step
OutputThe six digits match within one window and change in the next (verification should tolerate one window either side)

Measured on This Page

Cross-check vs. reference3 of 3 time windows matched exactly (RFC 6238 Appendix B secret)
Vector you can replaysecret ASCII "12345678901234567890", T=59 → 8-digit code 94287082
Last 90 days on Google22 clicks / 232 impressions / average position 8.1

Clock skew is the most common failure: a device that is one 30-second window behind will fail repeatedly, while the error message merely says "invalid code". The countdown and the "previous window" code on this page exist to tell the two apart.

How this was measured: In Chrome 155 we entered the RFC 6238 Appendix B secret and read the previous / current / next codes from the page, comparing them bit-by-bit against an independently written Python HMAC-SHA1 implementation; all computation runs locally in the browser, and re-entering the secret offline still generates valid codes. · Measured 2026-10-26

How to Use

  1. Open "OTP / TOTP Generator"
  2. Paste the Base32 secret and the code appears instantly
  3. Copy the current code from the icon beside it
  4. The code refreshes when the countdown reaches zero
  5. Use the previous and next window codes to check clock skew

Use Cases

  • Debug 2FA integration — Compute TOTP locally from the server-issued secret to confirm your verification logic matches the standard.
  • Cross-check authenticators — Compare codes from this tool with Google/Microsoft Authenticator to pinpoint time-drift issues.
  • Emergency code — When your phone is unavailable, generate the current code in the browser from a known secret to log in.
  • Automated testing — Produce predictable test codes for a 2FA-enabled account in a development environment.
  • Diagnose clock skew — Watch the remaining seconds and server rejections to tell whether clock desync causes failures.
  • Backup code test — Generate a TOTP code to verify that your backup 2FA recovery codes are stored correctly.
  • Secret rotation — Use a newly rotated Base32 secret to confirm the new code works before switching the server over.

FAQ

How do TOTP and HOTP differ?

HOTP (RFC 4226) uses an incrementing counter that steps each use; TOTP (RFC 6238) replaces the counter with current time divided by a period, so the code refreshes automatically over time, the mainstream choice for phone authenticators.

Why does my code not match the server?

The most common cause is clock desync. TOTP depends heavily on accurate time, and a drift of tens of seconds yields a different code. Sync your system clock; most servers also tolerate one window before and after.

Why is the secret in Base32?

2FA secrets are usually Base32 because it uses only uppercase letters and digits with no ambiguous characters, easy to share as a QR code or text. The tool decodes Base32 back to raw bytes before the HMAC.

What are the default digits and period?

The industry default is 6 digits, a 30-second period, and HMAC-SHA1 underneath, the standard for nearly all authenticators and services. Some systems use 8 digits or SHA256, which this tool can match.

Is generating codes in a browser safe?

The computation is local and the secret is not uploaded, but putting a 2FA secret in a browser weakens the isolation of the "second factor." Use it for debugging; for the long term, prefer a dedicated authenticator app or hardware key.

The generated codes are always rejected. What could it be?

In order of likelihood: the device clock is off, since these codes are derived from time steps and more than one step of drift fails continuously, so enable automatic time sync; the secret was entered with stray spaces or inconsistent case and needs normalizing; or the step size differs from the server, with thirty seconds common but not universal. Checking these three usually locates it.

Can the same secret generate identical codes on several devices?

Yes, provided the secret, step size and algorithm all match exactly. That is convenient and risky at once: every extra copy is another leak point. When using several devices, make sure each has its own unlock protection, revoke the secret promptly if a device is lost, and where the server supports it, enrol a separate secret per device rather than sharing one.

My generated code does not match the one on my phone?

TOTP is shared secret plus current time, so mismatches come from clock drift beyond the ±30s window or a mistyped secret. Sync the device clock via NTP first, then re-check the key — one wrong character and it never matches.