TOTP / 2FA Code Generator

Share:

Generate and verify TOTP codes (RFC 6238) entirely in your browser. Use for testing 2FA flows, not for production secrets.

RT-CW3-002 · Crypto & Web3
Your browser is too old for this tool’s interactive features. Please update to Safari 13.1, Chrome or Edge 80, Firefox 74 or newer.

TOTP Generator Tool

Privacy & safety: All TOTP computation happens inside your browser using the native SubtleCrypto API. Your secret never leaves this page. Do not use this tool with production-system secrets — paste it into your real authenticator app instead. This tool is for testing 2FA flows, learning, and integration verification only.
Current code
——————
30s remaining · drift-window prev: —————— · next: ——————

Generate a fresh random base32 secret + otpauth:// URI you can scan into Google Authenticator, 1Password, Authy, or any other TOTP app. The URI uses the algorithm, digits, and period selected in the Generate tab (defaults: SHA-1, 6 digits, 30 s).

Advertisement
After results · AD-W1 Responsive · Post-tool — peak engagement

How to use the TOTP generator

Generate code mode

Paste a base32 secret (e.g. the QR-secret your 2FA-enabled service shows when setting up authenticator apps). The current code updates live every second, with the previous and next-window codes shown for drift testing.

Verify code mode

Paste a secret and a code, click Verify, and see whether the code matches the current 30-second window or one window before/after (the RFC 6238-recommended drift tolerance, commonly implemented).

New secret mode

Generate a brand-new 160-bit random base32 secret plus the standard otpauth:// URI containing it. The URI is what you'd encode into a QR code for scan-to-add into Google Authenticator, 1Password, Authy, etc.

Test, but don't use in production

This tool is for testing TOTP flows, learning the protocol, and verifying your integration. Don't paste real production secrets into any browser tool — use a hardware authenticator or a dedicated password manager for live accounts.

Advertisement
After how-to · AD-W2 Responsive

TOTP — how time-based one-time passwords actually work

TOTP (Time-based One-Time Password) is the standard powering almost every "scan this QR code into your authenticator app" two-factor authentication flow on the modern web. Specified in RFC 6238 in 2011, it generates a fresh 6-digit code every 30 seconds from a shared secret known only to the user's authenticator app and the service's server. The codes are deterministic given the same secret and the same time — meaning Google's server and your Google Authenticator app independently compute the same digit string, without ever exchanging the code itself over the network. Loss of network connectivity does not break TOTP; only loss of clock sync does.

The algorithm in one paragraph

TOTP is HOTP (HMAC-based One-Time Password, RFC 4226) with the counter replaced by floor(unix_time / 30). The server and client both compute HMAC-SHA1 over that counter using the shared secret, then take the LOW-ORDER FOUR BITS of the last byte of the HMAC output (& 0x0f) and use that as an offset. Four bytes are read from there, and the high bit of the FIRST of those four is masked off (& 0x7f) so the result is always a positive 31-bit integer, which is then reduced modulo 10^digits. Those 4 bytes are interpreted as a 31-bit integer modulo 10⁶ to produce the 6-digit code. The entire computation is around 20 lines of JavaScript when SubtleCrypto handles the HMAC primitive for you. The current standard supports SHA-1, SHA-256, and SHA-512 variants; SHA-1 remains the default for compatibility with older authenticator apps.

Drift tolerance and the 30-second window

Real-world clocks aren't perfectly synchronised. A phone's clock might be a few seconds ahead or behind the server. A user might also start typing a code with 28 seconds left on the timer and finish typing 5 seconds after the window rolled over. To handle these, RFC 6238 §5.2 recommends that "at most one time step is allowed as the network delay" — the ±1-window tolerance commonly implemented, giving an effective 90-second acceptance band. The RFC leaves the exact out-of-sync limit to each validator, which can set it tighter or looser both forward and backward depending on its risk model.

Regulators and authenticator apps

Authenticator apps are widely accepted as a strong second factor for online banking and payment services — and because TOTP is an open standard, any RFC 6238-compliant app can serve that role.

What this tool is not

This is a learning / testing / integration-verification tool. It is not a production authenticator app. Paste a Google account's TOTP secret into this page and you have effectively stored that secret in your browser's tab memory — accessible to any browser extension with content-script permission, any cross-site-scripting vulnerability on any other page in the same browser session, and any malware capturing the page's DOM. For real accounts, use a dedicated authenticator app (Google Authenticator, Authy, 1Password, Bitwarden's built-in TOTP) or a hardware key (YubiKey). The tool above is for verifying that your server's TOTP implementation produces codes matching what the standard authenticator app would produce — a debugging tool, nothing more.

Thirty seconds is a default, and the whole standard fits in two short RFCs

01

TOTP was specified in RFC 6238 in 2011 and is HOTP (RFC 4226) with the counter replaced by floor(unix_time / 30). RFC 4226 runs to 37 pages and RFC 6238 to 16, most of it security analysis and test code.

02

The time step is configurable via the period parameter in the otpauth:// URI. 30 seconds is the RFC 6238 default, selected "as a balance between security and usability".

03

RFC 6238 §5.2 recommends that "at most one time step is allowed as the network delay" — the ±1-window drift tolerance commonly implemented, an effective 90-second acceptance band for 30-second codes.

04

The base32 alphabet (RFC 4648) is used for TOTP secrets because it's case-insensitive and avoids the 0/O and 1/l visual collisions of base64 — important for manual entry from printed setup pages.

05

RFC 4226 (R6) sets the secret length: it MUST be at least 128 bits, with 160 bits (20 bytes / 32 base32 characters) RECOMMENDED. This tool's new-secret mode generates 160-bit secrets.

06

TOTP is an open standard: any RFC 6238-compliant app produces the same codes from the same secret, so you are never locked into one vendor’s authenticator.

07

SHA-1 is still the default TOTP algorithm despite SHA-1's general collision weaknesses — RFC 6194 (2011) found "no indication that attacks on SHA-1 can be extended to HMAC-SHA-1", which is the construction TOTP uses.

08

Because TOTP is an open standard, a secret set up in one compliant authenticator app produces the same codes in any other compliant app.

09

The otpauth:// URI scheme is documented by Google in its Key Uri Format for Google Authenticator, not by the IETF; it carries the secret, issuer, algorithm, digits and period for scan-to-add.

10

NIST SP 800-63B classifies SMS/voice OTP as RESTRICTED — still permitted, but with extra obligations on the provider (risk notice, a non-restricted alternative, a migration plan). The 2025 revision (800-63B-4) retains the restriction and classifies all manually entered OTP, TOTP included, as not phishing-resistant.

Frequently asked questions

No — and we strongly advise against it. The secret enters your browser's tab memory and is accessible to any other JavaScript running on the page (browser extensions, malicious ads, XSS bugs). Use this tool with throwaway test secrets only. For real accounts, use Google Authenticator, Authy, 1Password, Bitwarden, or a hardware key.
HOTP (RFC 4226) uses a counter that increments by 1 every time you press the button on a hardware token. TOTP (RFC 6238) replaces the counter with floor(unix_time / 30), so the code rotates automatically every 30 seconds without user interaction. TOTP is by far the more common variant today.
RFC 6238 uses HMAC-SHA-1 by default and also allows HMAC-SHA-256 and HMAC-SHA-512. HMAC-SHA-1 has held up despite the collision attacks on SHA-1: RFC 6194 (2011) found no indication that those attacks extend to HMAC-SHA-1. Google's Key Uri Format page notes that its Google Authenticator implementations ignore the algorithm parameter, which is one reason many services keep SHA-1.
RFC 6238 §5.2 recommends that "at most one time step is allowed as the network delay". Commonly implemented as accepting the previous, current, and next window — an effective 90-second acceptance band tolerating clock skew between user and server. The RFC leaves the exact out-of-sync limit to each validator.
Codes will fail to verify because both sides compute against unix_time. Google Authenticator and most modern apps allow a manual "sync with Google servers" option. The right long-term fix is to enable automatic time-sync on your phone (Settings → Date & Time → Automatic).
Yes — TOTP is deterministic given the same secret and time. Many users scan the QR into both their phone and a backup device (1Password, a second phone, a YubiKey) for redundancy. The service has no way to detect this.
RFC 4226 (R6) sets the floor: "The length of the shared secret MUST be at least 128 bits. This document RECOMMENDs a shared secret length of 160 bits." This tool's new-secret mode generates 160-bit secrets (20 bytes / 32 base32 characters).
otpauth://totp/Issuer:account?secret=BASE32&issuer=Issuer&algorithm=SHA1&digits=6&period=30. The path part contains the account label, the query string contains parameters. Encoding this as a QR code is what enables scan-to-add into authenticator apps.
No. RFC 4226's Digit parameter allows 6, 7, or 8-digit codes — 6 is the required minimum. The digits parameter belongs to the otpauth:// URI convention, which documents values of 6 or 8. In practice 6 is overwhelmingly the standard.
Everything. The HMAC computation uses the browser's native SubtleCrypto API; the base32 decoder is pure JavaScript. Your secret never leaves the page. You can verify via the browser network tab — no requests fire while you generate or verify codes.

Method & sources

What this tool implements

  • The TOTP arithmetic had no test; it now runs all 18 RFC 6238 Appendix B vectors (SHA-1, SHA-256, SHA-512, including T = 20000000000 which needs the counter's high word). The clock now starts after the deferred kernel has loaded.
  • Corrected: 'the two RFCs fit in under 30 pages' (RFC 4226 is 37, RFC 6238 is 16); the otpauth URI is documented in Google's Key Uri Format, which also notes Google Authenticator ignores the algorithm parameter; HMAC-SHA-1 is cited to RFC 6194.
  • RFC 6238 quotes checked verbatim (30 s 'as a balance between security and usability'; 'at most one time step is allowed as the network delay'); RFC 4226 R6 secret length; NIST SP 800-63B-4 on manual-entry OTP not being phishing-resistant.

Sources

Advertisement
Pre-footer · AD-W3 728 × 90