PIN and recovery code generator
Generate random numeric PINs and sets of one-time recovery codes, such as 10 codes of 10 characters in groups. Unbiased, made in your browser, never sent.
- Entropy per code
- 49.5 bits
31 possible characters each, no look-alikes
The result appears here.On the server, store recovery codes hashed, accept each one once, and let the user make a new set, which cancels the old one. Compare without the hyphens.
Made in your browser with crypto.getRandomValues. Nothing is sent or stored.
Everything you type here stays in your browser. Nothing is sent to HardenKit or to anyone else.
How to use the PIN and recovery code generator
- Choose recovery codes or numeric PINs.
- Set the size: the number of codes, their length and grouping, or the number of digits.
- Press Generate.
- Copy the result. Reload the page and it is gone.
About this tool
Recovery codes are the spare keys of two-factor authentication: a set of one-time codes a user prints or saves, to get back in when the phone with the authenticator is lost. A numeric PIN is the short secret for places where a keyboard is awkward and guesses are limited. Both must come from a real random source, because people asked to choose pick birthdays and patterns, and the same few values come up again and again.
This tool draws every character with your browser’s cryptographic random generator and without modulo bias, so each digit and letter is equally likely. Recovery codes use 31 lowercase letters and digits with the look-alikes 0, o, 1, l and i left out, and are grouped with hyphens so they are easy to read and copy by hand. Ten characters give about 50 bits per code, ample for a code the server also rate-limits.
What you do with them matters as much. On the server, store recovery codes hashed, accept each exactly once, and replace the whole set when the user asks for new ones. A PIN is only as safe as the limit on attempts: four digits are 10,000 possibilities, fine for a card that locks after three tries and useless against anyone who can guess without limit. A random PIN can be 0000 or 1234; that is rare, and expected.
Sources
Questions
They are backup credentials for an account with two-factor authentication. Each code works once, in place of the code from an authenticator app or security key. Keep them somewhere separate from the device that holds your authenticator, such as on paper or in a password manager.
Long enough that guessing is hopeless even across a whole set and many accounts. Ten characters from a 31-character alphabet give about 50 bits each. With rate limiting on the login, that is far more than needed; without rate limiting, fix that first.
A 4-digit PIN has 10,000 possible values and a 6-digit PIN a million. That is secure only when the system locks or slows down after a few wrong tries. Against an attacker who can test guesses offline, any PIN falls at once.
Taking a random byte modulo 10 to get a digit makes 0 to 5 slightly more likely than 6 to 9, because 256 is not a multiple of 10. Over many codes that skew helps an attacker. This tool discards the values that would cause it and draws again, which keeps every outcome equally likely.