TOTP / 2FA Code Generator
Generate and verify TOTP codes (RFC 6238) entirely in your browser. Use for testing 2FA flows, not for production secrets.
TOTP Generator Tool
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).
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.
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
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.
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".
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.
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.
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.
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.
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.
Because TOTP is an open standard, a secret set up in one compliant authenticator app produces the same codes in any other compliant app.
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.
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
floor(unix_time / 30), so the code rotates automatically every 30 seconds without user interaction. TOTP is by far the more common variant today.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.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.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
- M'Raihi D, Machani S, Pei M, Rydell J. RFC 6238: TOTP: Time-Based One-Time Password Algorithm. IETF; May 2011. https://www.rfc-editor.org/rfc/rfc6238
- M'Raihi D, et al. RFC 4226: HOTP: An HMAC-Based One-Time Password Algorithm. IETF; December 2005. https://www.rfc-editor.org/rfc/rfc4226
- Josefsson S. RFC 4648: The Base16, Base32, and Base64 Data Encodings. IETF; October 2006. https://www.rfc-editor.org/rfc/rfc4648
- Polk T, Chen L, Turner S, Hoffman P. RFC 6194: Security Considerations for the SHA-0 and SHA-1 Message-Digest Algorithms. IETF; March 2011. https://www.rfc-editor.org/rfc/rfc6194
- Google Authenticator wiki. Key Uri Format. https://github.com/google/google-authenticator/wiki/Key-Uri-Format
- NIST SP 800-63B-4: Digital Identity Guidelines, Authentication and Authenticator Management. https://pages.nist.gov/800-63-4/sp800-63b.html
Pick up where you left off
Stored only in this browser — never sent to our servers.