TOTP Secret Generator
Generate a TOTP secret for two-factor authentication. Scan the QR code with Google Authenticator, Authy, or 1Password to set up 2FA.
How to Add to Your App
1. Generate the secret and store it securely in your database (encrypted at rest) linked to the user. 2. Show this QR code to the user once during setup — they scan it with their authenticator app. 3. On login, prompt for the 6-digit code and verify it server-side using a TOTP library (e.g. speakeasy for Node, pyotp for Python, GoogleAuthenticator for Java). Never regenerate the secret after setup — that invalidates the user's authenticator.
20-byte random secret established once — stored in Base32 in the authenticator app
T = floor(unix_timestamp / 30) — a counter that increments every 30 seconds
HMAC-SHA1(secret, T as 8-byte big-endian) — produces a 20-byte MAC
Last nibble of HMAC is the offset; 4 bytes starting at that offset are extracted
(extracted_value & 0x7FFFFFFF) mod 10^6 — the code shown in your authenticator
Spec: RFC 6238 (TOTP), RFC 4226 (HOTP), RFC 2104 (HMAC)