By Tim King · Updated
Backup Code Generator
Random 2FA Recovery Codes in Digits, Letters or Hex, With Entropy Shown
OneTask is free, with no sign-up, and built by one person.
If this tool saved you time, a coffee helps keep new ones coming.
How the Backup Code Generator works
This backup code generator produces a set of random recovery codes of the kind sites hand out when you turn on two-factor login. Choose the characters, the length and how they are grouped, and it shows how many bits of randomness each code carries.
What the backup code generator is for
Recovery codes let someone into an account when their phone is lost. If you are building 2FA, you need to issue them; if you are testing a flow, you need realistic ones. Each code comes from the browser's cryptographic random generator with rejection sampling, so every character is equally likely.
Choosing a format
Ten digits in two groups of five is the most common format, and easy to read out over the phone. The letters-and-digits set leaves out 0, O, 1, I and L so a printed code cannot be misread, and gives more entropy per character. Hex is handy when the codes are going straight into a database.
Storing them properly
Treat recovery codes like passwords. Hash each one before storing it, mark it used the moment it is accepted, and let users regenerate the whole set. With ten codes of 33 bits each, an attacker guessing at random has about one chance in three billion per guess — fine with rate limiting, not without it.
FAQ
How many backup codes should I issue?
Eight to ten is the usual number. It covers several lost-phone episodes without leaving a long list of valid secrets on a piece of paper. Show the user the full set once, and offer to regenerate it, which invalidates the old list.
Are these codes truly random?
Yes. They come from crypto.getRandomValues, the same source browsers use for encryption keys, and
rejection sampling removes the slight bias a plain modulo would add. They are generated on this page
and not sent or stored anywhere.
Why does the entropy figure matter?
It tells you how hard a code is to guess. Every extra bit doubles the work. Around 30 bits is acceptable for a code that is rate limited and single use; if codes could be attacked offline, use longer ones or the letters-and-digits set.
See also: all Security & Identifiers tools, Dev Utilities, Formatters & Validators, Data & Encoding, SEO, Accessibility, AI.
Related tools
TOTP Generator
Live two-factor codes from a base32 secret, with a countdown.
Random String Generator
Cryptographically random strings in any length and character set.
Password Generator
Strong random passwords generated in your own browser.
Account Security Checklist
A prioritised checklist to secure email, bank, social and work accounts.
Secret Splitter
Split a secret into shares; any threshold of them rebuilds it.