2FA Code Generator (TOTP)

Create a new authenticator secret with a scannable QR code, or paste an existing secret to see its live 6-digit codes. Codes are computed in your browser.

Secret

Scan the QR with Google Authenticator, Authy, 1Password or any TOTP app. Building a website? Use our free 2FA API.

Live code
------
30s until next code

Why the Code Changes Every 30 Seconds

The magic is that your phone and the server never talk to each other to agree on a code. They both already share two things: the secret (set when you scanned the QR) and the current time. TOTP just combines them:

  1. Take the Unix time and divide by 30 - That's the current "time step."
  2. Run HMAC-SHA1 over that number using the secret as the key.
  3. Truncate the result to 6 digits. Both sides compute the identical value.

Because the time step advances every 30 seconds, so does the code - And an old code is worthless the moment its window closes. This is also why authenticator apps beg you to keep your phone's clock accurate: if the clocks drift too far apart, the two sides compute different codes. Servers usually accept the adjacent window to forgive a few seconds of skew.

One consequence worth understanding: a stolen 6-digit code is nearly useless (it dies in under a minute), but a stolen secret lets an attacker generate valid codes forever. Guard the secret like a password; the codes protect themselves.

About TOTP Two-Factor Codes

How the 6 digits are made

TOTP (RFC 6238) combines your secret key with the current 30-second time window using HMAC-SHA1, then truncates the result to 6 digits. Because both your phone and the server know the secret and the time, they compute the same code - no network needed. That's why authenticator apps work in airplane mode.

This page runs the same algorithm with the Web Crypto API, entirely locally. Learn more in the complete 2FA guide and TOTP vs SMS.

Keep secrets secret

  • Treat the base32 secret like a password - Anyone holding it can generate your codes.
  • Save backup codes (or the secret itself) in an encrypted vault like the Password Wallet.
  • 2FA protects you even if your password leaks - Enable it on email first, since email resets everything else.
  • Never enter TOTP codes on a page reached from an email link - See the phishing guide.

How to Use the 2FA Code Generator

1

Generate or paste a secret

New secrets are 32 random base32 characters; or paste an existing secret to recover its codes.

2

Set issuer and account

These label the entry inside authenticator apps so users know which site it belongs to.

3

Scan the QR code

Google Authenticator, Authy, 1Password and every RFC 6238 app understand this format.

4

Verify a code

Type the current 6-digit code into the enrolling website - Or use our free 2FA API to verify it programmatically.

TOTP parameters used here (and by virtually every service)

ParameterValueWhy
AlgorithmHMAC-SHA1The RFC 6238 default every authenticator app supports
Digits6Standard balance of security and typability
Period30 secondsUniversal default - Codes rotate twice a minute
Secret length32 base32 chars (160 bits)Full HMAC-SHA1 key strength
Verify window±1 periodTolerates clock drift between devices

2FA Code Generator - FAQ

Do TOTP codes need an internet connection?
No. The code is computed from the shared secret plus the current time - That's why authenticator apps work in airplane mode. This page does the same computation locally with the Web Crypto API.
Is SHA-1 in TOTP a security problem?
No. TOTP uses HMAC-SHA1, which is not affected by SHA-1's collision attacks - Forging codes would require breaking the 160-bit secret itself. The entire authenticator ecosystem standardizes on it.
What happens if someone sees one of my codes?
A single code is valid for at most about 60 seconds and only together with your password. The real crown jewel is the base32 secret - Anyone holding it can generate codes forever, which is why it should live in an encrypted vault.
Can I use this to add 2FA to my own website?
Yes - That's what the free 2FA API is for: one endpoint creates secrets and QR codes at enrolment, another verifies submitted codes at login. No API key needed.

More questions about passwords and security? Browse the security guides.