Privacy and Security

How to Design Recovery Codes and Invite Codes People Can Type

Design backup recovery and invite codes: how much entropy you need, alphabets without confusable characters, check digits, grouping and hashing.

Saizul Amin
Saizul Amin30 Oct 2026 · 3 min read
How to Design Recovery Codes and Invite Codes People Can Type

How to Design Recovery Codes and Invite Codes People Can Type

When someone loses the phone that holds their two-factor app, a recovery code is often the only way back into their account. Invite codes, vouchers and activation keys work the same way: a secret printed on paper or shown on screen that a person types in later. Good codes must be impossible to guess and easy to type correctly. The free Recovery and Invite Code Generator produces codes that are both, and shows how strong they are.

How much randomness

Strength is measured in bits of entropy: each bit doubles the number of possible codes. A code of length n from an alphabet of k symbols has n times log2 k bits.

  • For account recovery, NIST guidance for look-up secrets asks for at least 64 bits. Sixteen characters from a 32-symbol alphabet give 80 bits, a comfortable margin.
  • For invite codes and vouchers, where each guess goes through a rate-limited form, 40 to 60 bits is usually plenty.

The generator uses the Web Crypto random number generator with rejection sampling, so every symbol is equally likely. Simpler code that takes a random number modulo the alphabet size slightly favours some symbols, which weakens the result.

Choosing an alphabet

People misread 0 and O, 1, I and l, and sometimes 5 and S or 8 and B. Good alphabets remove the worst offenders:

  • Crockford Base32 uses digits and capitals without I, L, O and U. When checking, it treats I and L as 1 and O as 0, so common mistakes still work.
  • Unambiguous alphanumerics drop 0, O, 1, I and L entirely.
  • Digits only suit phone keypads and spoken codes but need more characters for the same strength.

Upper-case codes in a monospace font, split into groups of four or five with hyphens, are the easiest to read and type.

Check characters

A check character at the end lets a form spot a typo before it queries the database. The generator uses the Luhn mod N algorithm, a generalisation of the check digit on bank cards that works with any alphabet. It catches every single wrong character and most swaps of neighbouring characters. It adds no security, because it is computed from the rest of the code, but it makes the experience much better when someone mistypes.

Collisions

With millions of codes, two might in theory be the same. The tool shows the chance of any duplicate in your batch using the birthday formula. With 50 or more bits per code and batches of thousands, the chance is negligible, but checking for duplicates before inserting codes into a database costs nothing.

Storing codes safely

Recovery codes are as powerful as passwords, so store them the same way:

  • Save a hash of each normalised code, never the code itself. The tool can export SHA-256 hashes alongside the codes.
  • When a code is entered, normalise it (remove spaces and hyphens, fix case), hash it and compare.
  • Mark each code as used after one successful login, and show people how many remain.
  • Show the codes once, offer download and printing, and let people generate a new set, which invalidates the old one.

Because recovery codes are random and long, a fast hash such as SHA-256 is acceptable here, unlike for passwords chosen by people.

Step by step

  1. Choose an alphabet and length, watching the entropy figure.
  2. Set grouping, a separator and an optional prefix.
  3. Add a check character if your form will validate it.
  4. Generate the batch and download it, with hashes if you need them.
  5. Use the check mode to test how typed codes are validated.

Privacy

Codes are created in your browser and are never sent to or stored on any server.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages