TOTP / 2FA Code Generator

Share:

Generate and verify TOTP codes (RFC 6238) entirely in your browser. Use for testing 2FA flows, not for production secrets.

RT-CW3-002 · Crypto & Web3

TOTP Generator Tool

Privacy & safety: All TOTP computation happens inside your browser using the native SubtleCrypto API. Your secret never leaves this page. Do not use this tool with production-system secrets — paste it into your real authenticator app instead. This tool is for testing 2FA flows, learning, and integration verification only.
Current code
——————
30s remaining · drift-window prev: —————— · next: ——————

Generate a fresh random base32 secret + standard otpauth:// URI you can scan into Google Authenticator, 1Password, Authy, or any other TOTP app.

Advertisement
After results · AD-W1 Responsive · Post-tool — peak engagement

How to use the TOTP generator

Generate code mode

Paste a base32 secret (e.g. the QR-secret your 2FA-enabled service shows when setting up authenticator apps). The current code updates live every second, with the previous and next-window codes shown for drift testing.

Verify code mode

Paste a secret and a code, click Verify, and see whether the code matches the current 30-second window or one window before/after (the standard drift tolerance most services accept).

New secret mode

Generate a brand-new 160-bit random base32 secret plus the standard otpauth:// URI containing it. The URI is what you'd encode into a QR code for scan-to-add into Google Authenticator, 1Password, Authy, etc.

Test, but don't use in production

This tool is for testing TOTP flows, learning the protocol, and verifying your integration. Don't paste real production secrets into any browser tool — use a hardware authenticator or a dedicated password manager for live accounts.

Advertisement
After how-to · AD-W2 Responsive

TOTP — how time-based one-time passwords actually work

TOTP (Time-based One-Time Password) is the standard powering almost every "scan this QR code into your authenticator app" two-factor authentication flow on the modern web. Specified in RFC 6238 in 2011, it generates a fresh 6-digit code every 30 seconds from a shared secret known only to the user's authenticator app and the service's server. The codes are deterministic given the same secret and the same time — meaning Google's server and your Google Authenticator app independently compute the same digit string, without ever exchanging the code itself over the network. Loss of network connectivity does not break TOTP; only loss of clock sync does.

The algorithm in one paragraph

TOTP is HOTP (HMAC-based One-Time Password, RFC 4226) with the counter replaced by floor(unix_time / 30). The server and client both compute HMAC-SHA1 over that counter using the shared secret, then take the last byte of the HMAC output, mask off the high bit, and use the result as an offset to extract 4 bytes from the HMAC. Those 4 bytes are interpreted as a 31-bit integer modulo 10⁶ to produce the 6-digit code. The entire computation is around 20 lines of JavaScript when SubtleCrypto handles the HMAC primitive for you. The current standard supports SHA-1, SHA-256, and SHA-512 variants; SHA-1 remains the default for compatibility with older authenticator apps.

Drift tolerance and the 30-second window

Real-world clocks aren't perfectly synchronised. A phone's clock might be a few seconds ahead or behind the server. A user might also start typing a code with 28 seconds left on the timer and finish typing 5 seconds after the window rolled over. To handle these, RFC 6238 recommends accepting codes from the immediately-previous and immediately-next 30-second windows as well as the current one. Most major services (Google, AWS, Microsoft 365, GitHub) implement this drift tolerance of ±1 window — giving an effective 90-second acceptance band. Some banking and high-security services tighten this to ±0 (current window only) or use ±2 (150-second band) depending on their risk model.

Why MAS and BNM mandates matter for ASEAN fintech

Singapore's Monetary Authority (MAS) requires two-factor authentication for retail banking and licensed payment services under MAS Notice 644 and the Technology Risk Management Guidelines. Malaysia's Bank Negara has equivalent requirements via the eKYC and RMiT (Risk Management in Technology) guidelines. Both regulators accept TOTP via authenticator apps as a compliant second factor — alongside SMS-OTP and hardware tokens. Singapore's Singpass MFA architecture uses a custom proprietary scheme, but most ASEAN consumer-fintech and e-wallet products (GrabPay, ShopeePay, Touch 'n Go) rely on TOTP behind the scenes for their backend service authentication, even when the consumer-facing factor is biometric or SMS-OTP.

What this tool is not

This is a learning / testing / integration-verification tool. It is not a production authenticator app. Paste a Google account's TOTP secret into this page and you have effectively stored that secret in your browser's tab memory — accessible to any browser extension with content-script permission, any cross-site-scripting vulnerability on any other page in the same browser session, and any malware capturing the page's DOM. For real accounts, use a dedicated authenticator app (Google Authenticator, Authy, 1Password, Bitwarden's built-in TOTP) or a hardware key (YubiKey). The tool above is for verifying that your server's TOTP implementation produces codes matching what the standard authenticator app would produce — a debugging tool, nothing more.

10 TOTP / 2FA facts

01

TOTP was specified in RFC 6238 in 2011 and is HOTP (RFC 4226) with the counter replaced by floor(unix_time / 30). The two RFCs together fit in under 30 pages.

02

The default 30-second window is configurable via the period parameter in the otpauth:// URI. 60 seconds is occasionally used by services that want fewer reads against backing crypto hardware.

03

Most major services accept codes from the current ±1 30-second window — effectively a 90-second drift tolerance. AWS GovCloud and some banking services tighten this to ±0.

04

The base32 alphabet (RFC 4648) is used for TOTP secrets because it's case-insensitive and avoids the 0/O and 1/l visual collisions of base64 — important for manual entry from printed setup pages.

05

The standard secret length is 160 bits (20 bytes / 32 base32 characters). Google generates 80-bit secrets (10 bytes / 16 base32 characters) — slightly weaker but still well above brute-force feasibility.

06

MAS Singapore and BNM Malaysia both accept TOTP authenticator apps as a compliant second factor for retail banking. Many regional fintechs run TOTP backstage even when the user-facing factor is biometric.

07

SHA-1 is still the default TOTP algorithm despite SHA-1's general collision weaknesses — HMAC-SHA1's security model doesn't rely on collision resistance, so it remains safe for TOTP.

08

Microsoft Authenticator, Google Authenticator, 1Password, Authy, and Bitwarden all implement the same RFC 6238 standard. A TOTP secret from one works in any of them.

09

The otpauth:// URI scheme was created by Google specifically for the QR-code flow. It's not an IETF standard but every major TOTP app supports it.

10

SIM-swap attacks have made SMS-OTP increasingly risky. NIST SP 800-63B recommends authenticator apps (TOTP / push) over SMS for any account with material risk.

Frequently asked questions

No — and we strongly advise against it. The secret enters your browser's tab memory and is accessible to any other JavaScript running on the page (browser extensions, malicious ads, XSS bugs). Use this tool with throwaway test secrets only. For real accounts, use Google Authenticator, Authy, 1Password, Bitwarden, or a hardware key.
HOTP (RFC 4226) uses a counter that increments by 1 every time you press the button on a hardware token. TOTP (RFC 6238) replaces the counter with floor(unix_time / 30), so the code rotates automatically every 30 seconds without user interaction. TOTP is by far the more common variant today.
HMAC-SHA1 is cryptographically sound for TOTP's use case — the security model doesn't depend on SHA-1 being collision-resistant. SHA-256 and SHA-512 variants exist but break compatibility with older authenticator apps. Most services stick with SHA-1 for maximum interoperability.
RFC 6238 recommends accepting codes from the immediately-previous and immediately-next 30-second windows as well as the current one. This gives an effective 90-second acceptance band, tolerating clock skew between user and server. Higher-security services may reduce this to ±0 (current window only).
Codes will fail to verify because both sides compute against unix_time. Google Authenticator and most modern apps allow a manual "sync with Google servers" option. The right long-term fix is to enable automatic time-sync on your phone (Settings → Date & Time → Automatic).
Yes — TOTP is deterministic given the same secret and time. Many users scan the QR into both their phone and a backup device (1Password, a second phone, a YubiKey) for redundancy. The service has no way to detect this.
The standard recommends 160 bits (20 bytes / 32 base32 characters). Google uses 80 bits (10 bytes / 16 base32 characters), which is still secure but the minimum we'd use for production. This tool generates 160-bit secrets by default.
otpauth://totp/Issuer:account?secret=BASE32&issuer=Issuer&algorithm=SHA1&digits=6&period=30. The path part contains the account label, the query string contains parameters. Encoding this as a QR code is what enables scan-to-add into authenticator apps.
No — RFC 6238 supports 6, 7, or 8 digit codes via the digits parameter. 6 is overwhelmingly the standard; 8 is occasionally seen in higher-security contexts. Most consumer authenticator apps don't display 7-digit codes at all.
Everything. The HMAC computation uses the browser's native SubtleCrypto API; the base32 decoder is pure JavaScript. Your secret never leaves the page. You can verify via the browser network tab — no requests fire while you generate or verify codes.

Related News

You may be interested in these recent stories from our newsroom.

View all news →
Advertisement
Pre-footer · AD-W3 728 × 90

75 more free tools

Calculators, converters, security tools — no signup.