Skip to content
Toolcroft

Password & Security

TOTP Code Generator (RFC 6238)

Generate TOTP authentication codes from a Base32 secret - RFC 6238 compliant. Shows the current code, next code, and countdown timer. Everything runs in your browser.

Security note: Only paste test or development secrets here. Use a dedicated authenticator app for real accounts. All computation is local - nothing leaves your browser.

The manual-entry key from your 2FA setup page. Spaces and hyphens are ignored.

Enter a Base32 secret above to generate codes.

What is TOTP?

TOTP (Time-based One-Time Password) is defined in RFC 6238 and builds on HOTP (RFC 4226). It generates a short numeric code that refreshes every 30 seconds (or configurable period) using a shared Base32 secret and the current UTC time. Authenticator apps like Google Authenticator, Authy, and Microsoft Authenticator implement TOTP.

How TOTP works

The algorithm has three steps. First, the current Unix timestamp is divided by the period (30 seconds) and truncated to produce a counter value T. Second, HMAC-SHA1 (or SHA-256/SHA-512) is computed over the 8-byte big-endian encoding of T, using the decoded Base32 secret as the key. Third, a dynamic truncation step extracts 4 bytes from the HMAC output and reduces them modulo 106 (or 108 for 8-digit codes) to produce the final code.

Privacy and security

All TOTP computation happens locally in your browser using the native Web Crypto API. Your secret key is never transmitted anywhere. However, your TOTP secret is equivalent to your two-factor authentication. Anyone who has it can generate valid codes. Only enter test or development secrets here, and use a dedicated authenticator app for real accounts.

Finding your Base32 secret

When you enable 2FA on a website, the setup page shows a QR code and usually a "Manual entry key" or "Secret key" link. This key is your Base32-encoded TOTP secret. It consists of uppercase letters A–Z and digits 2–7.

Common TOTP app comparison

AppBackup / syncMulti-deviceNotes
Google Authenticator Limited (Google Account sync added 2023) Yes (after sync) Simple; widely supported; early versions had no backup
Authy Encrypted cloud backup Yes Most convenient; cloud backup is convenient but a trust trade-off
Microsoft Authenticator Encrypted cloud backup Yes Integrates well with Microsoft accounts; also supports push 2FA
YubiKey (hardware) N/A (hardware token) Multiple keys recommended Highest security; phishing-resistant; requires physical device

Cloud-backup apps trade some security for convenience. A cloud-synced authenticator is easier to restore after a lost phone, but the backup itself becomes a target. For highest security, use a hardware key or an app with no cloud sync.

What happens when clocks drift

TOTP requires the client and server clocks to be closely synchronized. The TOTP standard allows servers to accept codes from the ±1 adjacent time window (i.e., codes valid up to 30 seconds before or after the current window), providing a 90-second acceptance window.

If your clock drifts beyond 90 seconds, valid codes will be rejected. To resync:

  • Windows: w32tm /resync in an elevated command prompt.
  • macOS: System Settings -> General -> Date & Time -> toggle "Set automatically."
  • Mobile: Settings -> General -> Date & Time -> toggle "Set automatically."

TOTP vs. SMS 2FA

TOTP is significantly more resistant to common attacks than SMS-based two-factor authentication:

  • SIM-swapping: attackers social-engineer mobile carriers into transferring your phone number to a SIM they control, intercepting all SMS codes. TOTP codes are not delivered via the carrier - they are generated locally - so SIM-swapping has no effect.
  • SS7 interception: the telecom signaling protocol has known vulnerabilities that sophisticated attackers can exploit to intercept SMS. TOTP is immune.
  • Phishing: both TOTP and SMS codes can be phished in real-time by adversary-in-the-middle attacks. Hardware security keys (FIDO2/WebAuthn) are the only phishing-resistant 2FA option.

Even imperfect TOTP is a major security improvement over SMS 2FA. Enable TOTP wherever it is offered, and reserve hardware keys for your most critical accounts.