JustGenerator
Security & Keys 100% Client-Side Privacy

OTP & TOTP Generator

Generate cryptographically random one-time passcodes for testing, or compute live 30-second RFC 6238 TOTP 2FA codes from any Base32 secret locally.

Generated One-Time Passcode

000000

Random OTP codes versus live RFC 6238 TOTP

The acronym OTP covers two very different mechanisms in production apps. One is a single-use verification code your backend generates at random, stores in Redis with a 5-minute TTL, and emails or texts to a user. The other is TOTP (Time-based One-Time Password, RFC 6238), where your server and an authenticator app share a Base32 secret key and independently compute the same 6-digit code from the current Unix timestamp every 30 seconds.

This page handles both. On the Random OTP tab, each character is drawn from crypto.getRandomValues() using rejection sampling. Why rejection sampling? If you generate a random byte (0 to 255) and take byte % 10, digits 0 through 5 appear slightly more often than 6 through 9 because 256 is not divisible by 10. Discarding bytes at or above 250 gives every digit an exact 10% probability.

Debugging a Base32 2FA secret locally

Switch to the Live TOTP tab when you are wiring up two-factor authentication with libraries like otplib, speakeasy, or Python's pyotp. Paste your Base32 secret (the default sample JBSWY3DPEHPK3PXP decodes to the ASCII string Hello! with two trailing bytes, a standard test key from early authenticator docs) and confirm that your backend generates the exact same 6-digit number during the same 30-second window.

A few details to watch if your codes do not match:

  • Spaces, hyphens, and lowercase letters in a Base32 secret are ignored here, while characters outside A-Z and 2-7 trigger a validation error.
  • Google Authenticator and Authy default to HMAC-SHA1, 6 digits, and a 30-second period. Some enterprise SSO tools switch to SHA-256 or 8 digits, which you can select directly in the dropdowns above.
  • If your backend code is consistently off by one cycle, check your server's NTP clock drift. Most production verifiers allow a window of plus or minus 1 step (30 seconds on either side) to handle minor phone clock skew.

Choosing character sets for human-typed codes

When users have to read a code off an email and type it on a phone keyboard, 6 numeric digits are the fastest to enter and trigger the numeric keypad on iOS and Android. If you need higher entropy for backup recovery codes, switch the Character Set dropdown to Readable (No 0/O/1/I/L) and generate a batch of 8-character or 10-character codes. Dropping lookalike characters prevents support tickets where someone types a capital letter O instead of zero.

Because every random byte and HMAC-SHA1 calculation runs inside your browser tab, staging secrets and recovery codes never touch a remote server. For long-lived API secrets rather than short user passcodes, use our Random Token Generator, and for storing passwords alongside 2FA, check our Bcrypt Hash Generator.

Common questions

What is the difference between TOTP and HOTP?

TOTP (Time-based One-Time Password, RFC 6238) generates a temporary code from a shared secret and the current Unix timestamp, rotating automatically every 30 seconds. HOTP (HMAC-based One-Time Password, RFC 4226) uses an incrementing counter instead of time, so the code only changes when a user requests or consumes a new one.

How does a TOTP authenticator code generator work?

Both your authenticator app and the login server store the same Base32 secret key. Every 30 seconds, each side divides the current Unix epoch time by 30, hashes that counter with the secret using HMAC-SHA1 (or SHA-256), and extracts a 6-digit or 8-digit number. Because both clocks match, they arrive at the exact same code offline.

Why do TOTP codes change every 30 seconds?

A 30-second window balances usability and security. It gives a human enough time to read six digits and type them into a login screen, while ensuring that an intercepted or shoulder-surfed code expires before an attacker can reuse it.

What is a Base32 secret key in 2FA setup?

When you enable two-factor authentication and click "Cannot scan QR code," the website displays a manual setup key written in Base32 (uppercase letters A through Z and digits 2 through 7). Base32 avoids confusing characters like 0, 1, 8, and 9 so humans can type the key accurately.

Why is my TOTP code failing or getting rejected by a server?

The most common cause is clock drift between your computer or phone and the server. Turn on automatic network time synchronization (NTP) in your operating system settings, and double-check that the secret key, digit length (6 vs. 8), and period (usually 30 seconds) match what your app expects.

Is TOTP safer than SMS one-time passcodes?

Yes. SMS OTPs travel over cellular networks and can be hijacked through SIM-swapping attacks or carrier social engineering. TOTP codes are computed locally on your device without sending a text message over the network, making them much harder for remote attackers to intercept.