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-Zand2-7trigger 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.