Use this when storing user passwords safely.
Password Hashing
1. Password hashing uses slow, salted, memory-hard KDFs.
2. Argon2id preferred; scrypt, bcrypt, PBKDF2 acceptable.
3. Tune cost to about 100–500 ms.
4. Rehash on login when upgrading.
5. Never fast hashes.
password + salt + cost → KDF → hash
Context & applicabilityCommon mistakes · platform/version boundaries
- One global salt (pepper) instead of a unique salt per user.
- Truncating passwords before hashing.
- Low work factors chosen years ago and never raised.
- Rehashing the existing hash with a new algorithm without wrapping properly — plan a migration on next login.
Operational reference
Fast context before you go deeper.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Use slow, salted algorithms.
- Never plain or fast hashes.
- Upgrade old hashes at login.
grep <user> /etc/shadow | cut -d: -f2 | cut -c1-3— algorithm prefix- App password storage (Argon2id/bcrypt/scrypt) — review
- Cost parameters — tuned
ReferenceWhy it matters1 section · depth on demand
Requirements
- Unique random salt per password (stops rainbow tables and identical-hash spotting).
- Slow, tunable algorithm: Argon2id (first choice), scrypt, bcrypt, or PBKDF2 where FIPS is required.
- Optional pepper (secret key stored outside the database).
- Rehash with stronger parameters when users log in.
OWASP minimums (2024): Argon2id m=19 MiB, t=2, p=1; bcrypt cost 10+; PBKDF2-HMAC-SHA256 600 000 iterations. Never encrypt passwords reversibly, and never use plain SHA-256 or MD5.
ReferenceImportant terms & boundaries2 sections · depth on demand
Recommended parameters (OWASP)
In depth
Password hashing stores passwords as slow, salted, one-way hashes so that a stolen database does not reveal them and guessing each password is expensive. Fast general-purpose hashes are unsuitable because attackers can test billions of guesses per second on GPUs.
| Function | Status | Notes |
|---|---|---|
| Argon2id | Recommended | Memory-hard; tune memory/time cost |
| scrypt | Good | Memory-hard |
| bcrypt | Acceptable | 72-byte input limit; cost 12+ |
| PBKDF2 | Acceptable (FIPS) | High iteration counts |
| yescrypt | Good | Default on several Linux distributions |
| Unsalted/fast hashes | Insecure | MD5, SHA-1, SHA-256 alone |
Use a maintained library (e.g. argon2-cffi, passlib, framework defaults), store algorithm parameters with each hash, and upgrade hashes transparently when users log in.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Hashing → Password Hashing. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://csrc.nist.gov/pubs/fips/180-4/upd1/final · confidence 94%