TOTP / 2FA Code Generator
TOTP / 2FA Code Generator
Generate and verify TOTP codes (RFC 6238) entirely in your browser.
TOTP Generator Tool
160-bit secret (the RFC 6238 test seed).
A vector loads the RFC's seed, 8 digits and Unix time 59, so the code shown can be compared with the first row of the table in RFC 6238 Appendix B. Leave the time blank for the live code.
Checked with the algorithm, digits and period set on the Generate tab.
Generate a fresh random base32 secret and the otpauth:// URI that carries it. Authenticator apps scan that URI as a QR code (this page does not draw one), or you can type the secret in by hand. The secret is as long as the hash output: 160 bits for SHA-1, the length RFC 4226 recommends, 256 for SHA-256 and 512 for SHA-512. The URI uses the algorithm, digits and period selected in the Generate tab.
How to use the TOTP generator
Generate code mode
Paste a base32 secret (e.g. the setup key your 2FA-enabled service shows beside its QR code). The current code updates every second, with the previous and next-window codes for drift testing, the time step T and the 8-byte counter the HMAC signs. A secret whose length is impossible in base32 is refused, and one whose last character looks mistyped is flagged. Type a Unix time to reproduce a code from a log, or load an RFC 6238 test vector to check this page, or your own implementation, against the standard.
Verify code mode
Paste a secret and a code, click Verify, and see whether the code matches the current window, the one before (RFC 6238 §5.2 allows one step of network delay) or the one after (a clock-drift allowance under §6). It uses the algorithm, digits and period set on the Generate tab, and says so.
New secret mode
Generate a random secret (160 bits for SHA-1, 256 or 512 for the others) from the browser's cryptographic random generator, plus the otpauth:// URI containing it. The URI is what you would encode into a QR code. If you chose options Google Authenticator is documented to ignore, the page lists them.
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. For live accounts, keep the secret in an authenticator app, a password manager with TOTP, or a hardware security key.
TOTP — how time-based one-time passwords actually work
TOTP (Time-based One-Time Password) is the usual standard behind the "scan this QR code into your authenticator app" step of two-factor sign-up. Specified in RFC 6238 in May 2011, it derives a new code every time step (30 seconds is the RFC's recommended default) from a secret shared by the authenticator and the service's server. The codes are deterministic given the same secret and the same time, so the server and the app compute the same digits independently, without exchanging the code over the network. Losing the network does not break TOTP; a wrong clock does.
The algorithm in one paragraph
TOTP is HOTP (HMAC-based One-Time Password, RFC 4226) with the counter replaced by floor(unix_time / period), the period being 30 seconds by default. The server and client both compute an HMAC over that 8-byte 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 and left-padded with zeros. RFC 6238 makes HMAC-SHA-1 the default and also allows HMAC-SHA-256 and HMAC-SHA-512; the FAQ below says why many services stay on SHA-1.
Drift tolerance and the 30-second window
The RFC separates two problems. The first is delay: a code typed near the end of a step can reach the server in the next one, so §5.2 tells the validator to compare it with "past timestamps that are within the transmission delay", and recommends "that at most one time step is allowed as the network delay". That is one step back, T−1. The second is clock drift, in §6: the validator sets a limit on how many steps a device may be out of sync, and the RFC adds: "This limit can be set both forward and backward" from the step calculated when the code arrives. Accepting the next step, T+1, is a drift allowance of that kind, not part of §5.2. The verifier on this page accepts T−1, T and T+1 and says which one matched, which at a 30-second period covers 90 seconds of codes. §5.2 also recommends the 30-second default, "selected as a balance between security and usability".
Strong, but not phishing-resistant
NIST SP 800-63B-4 says authenticators that involve the manual entry of an output, OTP authenticators included, SHALL NOT be considered phishing-resistant, because typing a code does not bind it to the session it is typed into: a fake login page can pass it straight on. TOTP still stops a stolen password on its own; it does not stop a convincing relay.
What this tool is not
This is a learning / testing / integration-verification tool. It is not a production authenticator app. Paste a real account's TOTP secret into this page and it sits in this tab's memory, where a browser extension with access to this page, any script running on this site, or malware on the device could read it. Other websites cannot: the browser's same-origin policy keeps their scripts out of this page. For real accounts, keep the secret in an authenticator app, a password manager with TOTP, or a hardware security key. The tool above is for checking that a TOTP implementation produces the codes the standard says it should: a debugging tool, nothing more.
Frequently asked questions
floor(unix_time / 30), so the code changes every 30 seconds (the default period) without anyone pressing a button.otpauth://totp/Issuer:account?secret=BASE32&issuer=Issuer&algorithm=SHA1&digits=6&period=30, as Google documents it in its Key Uri Format. The path is the label, the query string the parameters; base32 padding is left out. Neither the issuer nor the account name may contain a colon, so the page refuses one. The same document says Google Authenticator ignores the algorithm and period parameters, and the digits parameter on Android, which is why many services stay on SHA-1, 6 digits and 30 seconds; 6 digits and 30 seconds are also the format's stated defaults. Encoding the URI as a QR code is what enables scan-to-add.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, with 6 the default, and its note says Google Authenticator on Android and BlackBerry ignores it.Method & sources
What this tool implements
- Corrected 2026-11-05: the T = 20000000000 vector does not reach the counter's high word (its counter, 666 666 666, fits in 32 bits); it tests 64-bit time. The high word is now tested at a counter of 2^32.
- RFC 4226 R6: "the shared secret MUST be at least 128 bits" and 160 bits is RECOMMENDED. The page reports the bit length of any secret and flags one under 128 bits; its old default, JBSWY3DPEHPK3PXP, is 80. New secrets are as long as the hash output: 160 bits for SHA-1, 256 and 512 for SHA-256 and SHA-512. RFC 4648 §6: base32 input is whole octets, so the final unit of output is 8, 2, 4, 5 or 7 characters; a secret 1, 3 or 6 characters past a multiple of 8 is refused (since 2026-11-21; it used to decode silently to a shorter key). §3.5: pad bits "MUST be set to zero by conforming encoders"; the page decodes a secret whose last character breaks that, and flags it as probably mistyped.
- RFC 6238 §5.2: 30 seconds is the default step, "selected as a balance between security and usability"; for network delay the validator compares "past timestamps that are within the transmission delay", and "at most one time step is allowed as the network delay", i.e. T−1. §6: the out-of-sync limit for clock drift "can be set both forward and backward". The verifier accepts T−1, T and T+1 (T+1 as a §6 drift allowance) and says which matched. Corrected 2026-11-21: the whole window had been credited to §5.2. The step is Unix time, never the local or business day.
- otpauth:// URIs follow Google's Key Uri Format (read 2026-11-05): label issuer:account, neither of which "may themselves contain a colon" (refused), base32 padding omitted, digits documented as 6 or 8. The same page says Google Authenticator ignores the algorithm and period parameters, and digits on Android; the page lists whichever of those the chosen options trigger.
- HMAC-SHA-1 remains the default: RFC 6194 §3.3 found "no indication that attacks on SHA-1 can be extended to HMAC-SHA-1". NIST SP 800-63B-4: authenticators involving manual entry of an output, OTP included, "SHALL NOT be considered 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