Password salts: how to generate and store a unique salt
Learn how salts reduce cross-account hash reuse, how to generate and store one per password, and how salts differ from peppers.
Password salts: how to generate and store a unique salt
A password salt is a per-password random value processed with the password before hashing. If two people choose the same password, different salts normally produce different stored hashes. A salt is not a secret key: it can be stored beside the hash. Generate a fresh cryptographically secure random salt for each password and do not reuse it.
Why salts matter
Without salts, identical passwords can produce identical hashes. Someone who obtains a database may spot accounts with matching passwords or compare hashes with precomputed lists. A distinct salt changes each calculation, making precomputed lists much less useful and comparisons across accounts harder. It does not make a weak password strong or stop guessing: an attacker can include the public salt when testing candidates. A purpose-built, deliberately costly password-hashing scheme is also needed.
Generate and store safely
Generate a new salt with the system cryptographic random-number generator. Do not use a username, timestamp, counter, or other predictable value.
Do not reuse salts across passwords. A password change should create a new salt and hash record.
Store the salt and result with the scheme name/version and cost parameters. The salt is public metadata, not a secret that belongs in a key vault.
Prefer a maintained password-hashing API that generates and encodes salts for you. Check its documentation; avoid implementing salt generation or hash composition yourself.
Configure the scheme's cost too. A salt limits precomputation; the cost factor slows each individual guess. They provide different protections.
NIST SP 800-63B-4 requires a salt of at least 32 bits, selected to minimize collisions among stored hashes, and requires storing each salt with its resulting hash. It recommends recording scheme and cost metadata to support migration. Follow current applicable standards and validated library guidance.
Salt and pepper
A salt is a public random value unique to each password. A pepper is an additional service secret used in a keyed-hash or encryption step and kept separate from the password database. NIST recommends such a verifier-only secret key. If used, it adds key storage, rotation, and recovery responsibilities; it does not replace salts.
Sources
[NIST SP 800-63B-4: Authenticator and Verifier Requirements](https://pages.nist.gov/800-63-4/sp800-63b/authenticators/)
[NIST SP 800-63B-4: Strength of Passwords](https://pages.nist.gov/800-63-4/sp800-63b/passwords/)