SECURITY TOOL

TOTP Generator

Generate Time-based One-Time Passwords compatible with Google Authenticator, Authy, and other 2FA apps. Live countdown with configurable period and digit count.

Enter or generate a secret key, then click “Start TOTP”

TOTP: The Math Behind Your Authenticator App

How TOTP Works (RFC 6238)

TOTP = HMAC-SHA1(secret, floor(time / 30)) mod 106

TOTP divides time into 30-second windows. The current Unix timestamp is divided by 30 to get a counter value. This counter and the shared secret are fed into HMAC-SHA1, producing a 160-bit hash. The last 4 bits determine an offset into the hash; 4 bytes at that offset are extracted as a 31-bit integer, then reduced modulo 106to get the 6-digit code. Both the server and your authenticator app compute the same code independently — no network communication needed.

The Secret Key

The secret is a Base32-encoded random value, typically 20 bytes (160 bits) providing 2160 possible keys. It is shared once during 2FA setup (usually via QR code containing an otpauth:// URI). The secret must be stored securely on both the server and the client device. If an attacker obtains the secret, they can generate valid codes. This is why backup codes exist — they provide an alternative if the device with the secret is lost.

Clock Drift and Time Windows

If the server and client clocks are slightly out of sync, the code might not match. Servers typically accept codes from the current window plus the previous and next windows (a 90-second tolerance). NTP (Network Time Protocol) keeps most devices within milliseconds of UTC, but mobile devices can drift if NTP is disabled. A server-side time-drift detection algorithm adjusts the accepted window per user to minimize false rejections while limiting replay attacks.

TOTP vs FIDO2/WebAuthn

TOTP is phishable: an attacker can create a fake login page, capture the TOTP code you enter, and relay it to the real site in real-time. FIDO2/WebAuthn(hardware keys like YubiKey, or passkeys) is phishing-resistant because the browser cryptographically binds the authentication to the site's origin. TOTP remains widely deployed due to its simplicity and compatibility with any device that has a clock, but FIDO2 is the stronger option where supported.

Frequently Asked Questions

Why are most TOTP codes only 6 digits?

Six digits provide 1 million possible codes per 30-second window. An attacker has a 1-in-1,000,000 chance of guessing correctly (0.0001%). Combined with rate limiting (typically 3-5 attempts before lockout), this provides strong security. Eight-digit codes reduce the probability to 1-in-100,000,000 and are used in some enterprise applications. The RFC supports any digit count.

Can I use the same secret in multiple authenticator apps?

Yes. The secret is just a Base32 string — you can enter it in Google Authenticator, Authy, 1Password, and Bitwarden simultaneously. They will all generate the same codes. This is also why you should scan the QR code with your backup method during setup, before dismissing the setup page.

Why does this tool use HMAC-SHA1 if SHA-1 is deprecated?

SHA-1 is deprecated for collision resistance (creating two inputs with the same hash), not for HMAC. HMAC-SHA1 is used differently than raw SHA-1 — it computes a keyed hash where the attacker doesn't control both inputs. No practical attack against HMAC-SHA1 exists. The RFC mandates HMAC-SHA1 for compatibility with Google Authenticator, though some implementations support HMAC-SHA256 or HMAC-SHA512 as options.