What this tool does
It computes the one-time codes of two-factor authentication the way authenticator apps and servers do, so you can test an integration without a phone in your hand. It generates a secret, shows the current TOTP code with the previous and next one, checks a code the way a server would, builds the otpauth:// URI that enrolment QR codes carry and draws that QR code. A second tab encodes and decodes Base32, the format 2FA secrets are written in.
Everything runs in this browser tab: the codes come from the browser's Web Crypto HMAC, and the QR code is drawn on a canvas by qrcode-generator, an MIT-licensed script served from this site. The tool itself makes no network requests: what you type stays in this browser tab. If you have allowed analytics cookies, Google Analytics sends its usual page-view and scroll events; they do not include what you type. Only three settings are kept in this browser's local storage: the verify window, the Base32 options and the last tab you used. Secrets, codes, URIs and the issuer and account names are never stored, unless you download the QR image, which then holds the secret. The fields also ask the browser not to spell-check, autocomplete or remember them.
How the codes are made
HOTP (RFC 4226)
The secret key K and an 8-byte big-endian counter C go into HMAC-SHA-1. The last 4 bits of the 20-byte result give an offset; the 4 bytes at that offset, with the top bit cleared, form a 31-bit number; the code is that number modulo 10digits, padded with leading zeros. The counter moves on each time a code is used.
TOTP (RFC 6238)
TOTP is HOTP with the counter replaced by the time step T = floor((unix time - T0) / X), where X is the period (30 seconds by default) and T0 is 0. Every party with the same secret and a correct clock gets the same code during the same 30 seconds. RFC 6238 also allows HMAC-SHA-256 and HMAC-SHA-512.
How to read the results
- Current code: the code for the step that contains the time shown. The ring and the seconds count show when it changes; with reduced motion turned on in your system, only the number is shown.
- Previous and next code: the neighbouring steps, the ones a server usually accepts to allow for clock drift and typing time.
- Time step T: the counter that went into HMAC, in decimal and as the 16 hex digits RFC 6238's test table uses.
- Verify: says which step matched (for example "previous step, T − 1") or that none did. For HOTP it looks ahead only, from the counter up.
- Fixed time: computes the code at any Unix time or UTC date instead of now, for reproducing a log line or a test vector.
Worked examples
These are this tool's own results for the inputs shown.
TOTP, secret GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ (the ASCII text 12345678901234567890), SHA-1, period 30
| Time | T (hex) | 8 digits | 6 digits |
|---|---|---|---|
59 | 0000000000000001 | 94287082 | 287082 |
1111111109 | 00000000023523EC | 07081804 | 081804 |
1234567890 | 000000000273EF07 | 89005924 | 005924 |
The 8-digit values are rows of RFC 6238 Appendix B. The 6-digit code is the last six digits of the 8-digit one, because both come from the same 31-bit number. Note the leading zeros: a code is a string, never a number.
HOTP, same secret, counter 0, step by step (RFC 4226 Appendix D)
HMAC-SHA-1 cc93cf18508d94934c64b65d8ba7667fb7cde4b0
offset 0xb0 & 0x0f = 0
4 bytes cc93cf18, top bit cleared: 4c93cf18 = 1284755224
code 1284755224 mod 10^6 = 755224
otpauth URI, issuer Example, account [email protected], the secret above
otpauth://totp/Example:alice%40example.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=Example&algorithm=SHA1&digits=6&period=30
The label is issuer, colon, account, each percent-encoded. The issuer is repeated as a parameter, as the format recommends. The secret is written without = padding. For HOTP the URI carries counter=0 instead of period.
Base32 of the text foobar (RFC 4648 section 10)
| Base32, padded | MZXW6YTBOI====== |
|---|---|
| Base32, no padding | MZXW6YTBOI |
| Base32hex, padded | CPNMUOJ1E8====== |
A mistyped secret, GEZDGNBVGY3TQOJ0
Secret: "0" at position 16 is not a Base32 character. Base32 has no 0: did you mean the letter O?
The Base32 alphabet of RFC 4648 is A to Z and 2 to 7, so 0, 1, 8 and 9 never appear; a 0 or a 1 in a secret is almost always a mistyped O, I or L. Instead of guessing, the tool names the character and its position.
Edge cases and pitfalls
- Clock drift. TOTP only works when both clocks agree. This page uses your device clock and cannot check it without contacting a server, which it does not do. If a code is rejected, compare the device time with an NTP-synchronised server before you suspect the secret.
- Replay within a step. A code stays valid for the whole step, and longer with a window. RFC 6238 section 5.2 says a verifier must not accept the same code twice: store the last step that succeeded per user and refuse codes from that step or earlier.
- The window is a trade-off. Accepting ±1 step tolerates 30 seconds of drift and slow typing; every extra step widens the time an observed code is useful. For HOTP the server looks ahead from the stored counter (RFC 4226 section 7.4) and moves the counter past the code that matched.
- 32-bit time and counters. The step is an 8-byte number. Code that stores time in a signed 32-bit integer breaks in January 2038; the RFC's row for time 20000000000 (year 2603) catches that. This tool uses exact 64-bit integers for counters and times.
- Key length. RFC 4226 requires at least 128 bits and recommends 160; RFC 6238 recommends a key as long as the hash output (20 bytes for SHA-1, 32 for SHA-256, 64 for SHA-512). The generator follows the selected algorithm, and shorter pasted keys get a warning.
- The RFC 6238 test seeds differ per hash. The appendix text names one 20-byte seed, but its SHA-256 and SHA-512 rows were computed with that ASCII string repeated to 32 and 64 bytes, as the reference code shows (verified erratum 2866). Use those seeds when you test your own implementation.
- Settings apps may ignore. Some authenticator apps ignore
algorithm,digitsandperiodand always use SHA-1, 6 digits and 30 seconds. Test enrolment with the apps your users have before you choose anything else. - Base32 padding and case. Secrets are usually shown without
=and in groups of four. The tool accepts both forms and lower case, but refuses a=in the middle, a wrong number of=, and lengths no encoder can produce (a last group of 1, 3 or 6 characters), which usually means a character was lost in copying. - Duplicated URI parameters.
secret=A&secret=Bis refused: apps disagree on which one wins. Unknown parameters such asimageare ignored and listed. A+in a parameter is read as a space, the form encoding most generators use; write a literal plus as%2B.
Standards used
- RFC 4226HOTP: HMAC-based one-time password, truncation, resynchronisation (section 7.4), test values (Appendix D)
- RFC 6238TOTP: time-based one-time password, time step, replay (section 5.2), test vectors (Appendix B)
- RFC 4648Base32 (section 6), Base32hex (section 7), test vectors (section 10)
- RFC 2104HMAC
- RFC 3986URI syntax and percent-encoding
- Key Uri FormatThe otpauth:// format, a Google Authenticator wiki page (not an RFC) that other apps follow
The engine is tested against all 18 rows of RFC 6238 Appendix B, the ten HOTP values and intermediate HMAC values of RFC 4226 Appendix D, the Base32 and Base32hex vectors of RFC 4648 section 10, and 1,300 TOTP and HOTP cases computed with Python's hmac module, including counters up to 264 − 1.
Frequently asked questions
Why does my server reject a code this page shows?
Check in this order: the clocks (a few seconds is fine, a minute is not), the secret (decode both to hex and compare: a single wrong character changes every code), then the algorithm, digits and period on both sides. A secret stored as the Base32 text instead of the decoded bytes is a common bug: HMAC then runs with the wrong key.
Is the secret Base32 text or bytes?
Bytes. Base32 is only how the bytes are written for people and QR codes. HMAC uses the decoded bytes, which the "Secret (hex)" row shows. If your library takes a key string, find out which of the two it expects.
How long should a TOTP secret be?
At least 16 bytes (128 bits), as RFC 4226 requires; 20 bytes is the usual value for SHA-1 and the most widely supported. Generate it with a cryptographic random generator, never from a password or user data.
What is the difference between TOTP and HOTP?
HOTP codes are counted: each use moves a counter, and a code stays valid until it is used. TOTP codes are timed: each one is valid for one period. TOTP needs synchronised clocks; HOTP needs the counter on the server to keep up with the device, which is why servers look ahead a few counters.
How many steps should a server accept?
One step either side is the common choice and what RFC 6238 section 5.2 suggests as a balance. Accept more only if you see real clock problems, and always refuse a code from a step that was already used.
Can I put this QR code in my app's enrolment page?
For testing, yes. In production your server should create the secret, store it encrypted, and render the QR code itself, so the secret never passes through a third-party page. The URI this page builds shows the exact format to produce.
Does anything I type here reach your server?
No. The codes, the QR code and the Base32 conversions are computed in your browser. The tool itself makes no network requests: what you type stays in this browser tab. If you have allowed analytics cookies, Google Analytics sends its usual page-view and scroll events; they do not include what you type. The page has no share link, because a link would carry the secret, and local storage holds only the verify window, the Base32 options and the last tab. Loading the page is counted in the site's usage statistics, as on every tool page, and what you type is not part of that record.