Password hashing and salts
Store a verifier, not a password
A login service needs to decide whether a supplied password is correct, not recover the original. Store an encoded result of a dedicated password hashing algorithm, including its salt, algorithm version and cost settings. A fast SHA-256 digest alone is unsuitable because verification is too cheap. Reversible encryption creates an unnecessary decryption dependency. A stolen verifier still creates guessing risk; hashing is not a substitute for access controls.
Salt and pepper
A salt is a random per-record value generated by a trusted library; it can be public and stored beside the verifier. Two users choosing the same password should receive different records. A pepper is optional secret material protected separately from the password database. It needs a documented rotation and compromise plan; do not build a custom pepper construction. A salt does not make weak passwords strong.
Local verification example
Use argon2-cffi 25.1.0 in an approved local environment. The following fictional input is public, never a real credential. hash generates its own salt; verify returns True on success and raises VerifyMismatchError for an incorrect password. Do not log either input or encoded verifier.
from argon2 import PasswordHasherfrom argon2.exceptions import VerifyMismatchErrorph = PasswordHasher()record = ph.hash("fictional classroom input")assert ph.verify(record, "fictional classroom input")try: ph.verify(record, "different classroom input")except VerifyMismatchError: print("Rejected")Expected output: Rejected. Other verification errors must also fail closed at the application boundary; this snippet illustrates only a known valid record.
Protect login and recovery
Combine password verification with attempt throttling, compromised-password screening at enrollment and appropriate MFA. Recovery proves account control using a separate approved process, then replaces the password; it never sends the old password back. Expire single-use reset authorization and invalidate it after use. Avoid account enumeration through response wording and timing; monitor abuse without recording secrets.
Practice: compare three records
A fictional portal proposes encrypted passwords, unsalted fast digests, or salted Argon2id verifiers with reviewed settings. Choose the third and explain why the others do not meet the authentication requirement. List two protections still needed after database theft. Consult the OWASP Password Storage guide (observed 2026-11-27) and NIST SP 800-63B-4 for the applicable policy.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Password hashing and salts — knowledge check
Apply password, certificate and key lifecycle principles to fictional scenarios.
What belongs in a password record?
What is a salt?
Where is an optional pepper protected?
What should recovery do?
What does a salted verifier not eliminate?