TOTP / 2FA Code Generator

Share:
Cybersecurity Tools

TOTP / 2FA Code Generator

Generate and verify TOTP codes (RFC 6238) entirely in your browser.

By Checked against sources by Last reviewed 2FA CRYPTO TOTP
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.

160-bit secret (the RFC 6238 test seed).

RFC 6238 test vector

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.

Current code
——————
30s remaining · drift-window prev: —————— · next: ——————
Time step T = — · counter —

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.

📅 Research current as of 21 Nov 2026 · Sources: RFC 6238 (TOTP) Appendix B vectors, §5.2 and §6; RFC 4226 (HOTP) §5.3, R6 and Appendix D; RFC 4648 §3.5 and §6 base32; Google Key Uri Format (github.com/google/google-authenticator/wiki), read 5 Nov 2026, for the otpauth:// URI and what Google Authenticator ignores; NIST SP 800-63B-4 on phishing resistance
Standards, published formulas, and reference data are revised over time — check against a current authoritative source before relying on these figures.
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 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.

Advertisement
After how-to · AD-W2 Responsive

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

No. The secret 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. Use this tool with throwaway test secrets only. For real accounts, keep the secret in an authenticator app, a password manager with TOTP, or a hardware security 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 changes every 30 seconds (the default period) without anyone pressing a button.
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.
Two allowances, in two sections of RFC 6238. §5.2 covers network delay and looks back only: it recommends "that at most one time step is allowed as the network delay", so the previous step (T−1) is accepted. §6 covers clock drift: each validator sets how many steps a device may be out of sync, a limit that "can be set both forward and backward". This page accepts T−1, T and T+1, and the next step is that drift allowance. At a 30-second period the three steps cover 90 seconds of codes.
Codes fail to verify, because the app and the server each compute the step from their own clock. A validator's drift allowance (RFC 6238 §6) absorbs a small error, not a large one. The fix is to turn on automatic date and time in the phone's settings.
Yes. A code depends only on the secret and the time, so every device holding the same secret shows the same code in the same step, and the code itself carries nothing about which device made it. Adding the secret to a second device at setup is one way to keep a backup.
RFC 4226 (R6) sets the floor: the shared secret "MUST be at least 128 bits", and the RFC recommends 160. This tool's new-secret mode generates 160 bits (32 base32 characters) for SHA-1 and the hash's output length for SHA-256 and SHA-512. The tutorial favourite JBSWY3DPEHPK3PXP is only 80 bits, under that floor, and the page says so if you paste it.
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.
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, with 6 the default, and its note says Google Authenticator on Android and BlackBerry ignores it.
Everything that touches the secret. The HMAC uses the browser's native SubtleCrypto API and the base32 decoder is plain JavaScript in this page. The secret and the codes are never put in a request, the address bar or browser storage. The page does make its ordinary requests (for example performance measurement), and none of them carries what you type.

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

Advertisement
Pre-footer · AD-W3 728 × 90