2FA Code Generator (TOTP)

Enter a secret key to get 6-digit codes, calculated in your browser

Calculated in your browser, never uploaded

This 2FA code generator turns the secret key a website gives you into the same 6-digit codes your authenticator app shows. It follows the RFC 6238 (TOTP) standard, refreshes every 30 seconds and runs entirely in your browser, so the key is never uploaded or stored.

How do I use the 2FA code generator?

Paste the secret key into the box above and the code appears immediately, refreshing every 30 seconds. You can also paste an otpauth:// URI, and the digits and period are filled in for you.

  1. On the site you are securing, turn on two-step verification and choose "Can't scan the QR code?" or "Enter key manually". The string of letters and numbers shown is the secret key.
  2. Paste the key into the box above. Upper or lower case and spaces don't matter.
  3. Enter the 6-digit code on the site to finish setup or sign in. When the countdown bar runs out, the next code appears automatically.
  4. To try it first, press "Use sample key" or "Generate random key". Neither belongs to any account.

How are TOTP codes calculated?

TOTP (Time-based One-Time Password) is the RFC 6238 standard published by the Internet Engineering Task Force (IETF) in 2011, built on RFC 4226 (HOTP) from 2005. The website and your device hold the same key and read the same clock, so they compute the same number. The key appears only once during setup and never has to travel over the network again.

  1. Divide the current Unix time (seconds since January 1, 1970 UTC) by 30 and keep the whole number as the counter.
  2. Compute HMAC-SHA1 of the counter using the key, which gives a 20-byte result.
  3. Use the last 4 bits of the result to pick an offset, read a 31-bit integer from there, and keep its last 6 digits. That is the code.
SettingMost commonOther options
Digits6 digits8 digits
Period30 seconds60 seconds
AlgorithmSHA-1SHA-256, SHA-512
Key formatBase32 (A–Z, 2–7)The secret parameter of an otpauth:// URI

Most websites use the settings in the first column. If a site says it uses 8 digits or 60 seconds, change them under Advanced settings above, or the numbers will not match.

Examples

  • Sample key JBSWY3DPEHPK3PXP: a public key used in many developer guides. Paste it and you will see a 6-digit code that changes every 30 seconds, which confirms the tool is working.
  • RFC 6238 test data: with the key GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ (the ASCII string "12345678901234567890"), Unix time 59, 8 digits and SHA-1, the code is 94287082, exactly as listed in Appendix B of the standard. Our calculation code is tested automatically against this data.

What should I keep in mind when using it?

  • The key is the key to your second lock: anyone who has it can generate your codes at any time. Never share it or paste it into a chat.
  • Use it only on your own device: never enter a key on a public, shared or borrowed computer.
  • Use an authenticator app for everyday sign-ins: this tool is best for occasional checks, testing, or confirming that a backed-up key is correct.
  • Isolated by design: the input area runs in a separate sandboxed frame that ad and analytics scripts on this page cannot read. The frame makes no network requests and stores nothing.
  • If codes don't match, check the clock first: an inaccurate device clock produces wrong codes, so turn on automatic time.

Frequently Asked Questions

Is my secret key uploaded or stored?

No. Codes are calculated on your device with the browser's built-in Web Crypto. Nothing is sent over the network or saved in the browser, and everything is cleared when you reload or close the page.

Why doesn't the code match the website?

The most common cause is an inaccurate device clock, because TOTP depends on time. Also check that the digits, period and algorithm match the site's settings.

Can this tool replace an authenticator app?

We don't recommend it. An authenticator app keeps the key on your phone, which is safer than pasting it into a web page each time. This tool suits occasional checks, testing or verifying a backup.

What if I lose my secret key?

Sign in with the backup codes the site gave you, or follow its account recovery process. Then set up two-step verification again and back up the new key and codes safely.

Why are codes usually 6 digits?

RFC 4226 requires codes of at least 6 digits, and most sites use 6 digits that change every 30 seconds. A few services use 8 digits or 60 seconds, which you can set under Advanced settings.

Sources: IETF RFC 6238: TOTP: Time-Based One-Time Password Algorithm; IETF RFC 4226: HOTP: An HMAC-Based One-Time Password Algorithm.

Related tools