Generates auth codes that are easy to read aloud, type, and remember — like
BOLD-MAPLE-0 instead of 483920.
Deterministic, stdlib-only, no dependencies.
pip install git+https://github.com/clemensjl/authcodegenerator.gitRequires Python 3.9+.
Same secret and identifier always give the same code:
>>> from authcodegenerator import generate_auth_code
>>> generate_auth_code("my-secret", "alice@example.com")
'BOLD-MAPLE-0'
>>> generate_auth_code("my-secret", "alice@example.com")
'BOLD-MAPLE-0'A different identifier gives a different code:
>>> generate_auth_code("my-secret", "bob@example.com")
'TOUGH-MOTH-2'Use the optional counter to issue several codes for the same identifier
(like an HOTP counter):
>>> generate_auth_code("my-secret", "alice@example.com", counter=1)
'FAST-MIST-5'
>>> generate_auth_code("my-secret", "alice@example.com", counter=2)
'STOIC-CREST-0'Invalid input raises: non-str secret/identifier or non-int counter
raise TypeError, a negative counter raises ValueError.
- Build the message
identifier + b"\x00" + counter(8-byte big-endian). - HMAC-SHA256 it with the secret to get a 32-byte digest.
- Take three non-overlapping slices of the digest and reduce each modulo its alphabet: bytes 0–1 pick an adjective (81 words), bytes 2–3 pick a noun (118 words), byte 4 picks a digit (0–9).
- Join them as
ADJECTIVE-NOUN-DIGIT.
That is 95,580 possible codes, so it is a memorable challenge code, not a replacement for a high-entropy secret. Keep the secret private — anyone holding it can compute every code.
pip install -e ".[dev]"
python -m pytestSee CONTRIBUTING.md for how to send a change.
MIT, see LICENSE.