Three kinds of hash, two of them wrong
Password hashing is one of the few areas of application security with a settled answer. No architectural trade-off, no dependence on context: there are three correct choices and everything else is wrong.
What makes people choose wrongly is that the word "hash" carries two entirely different meanings:
| Kind | Examples | Designed to be | Use for passwords? |
|---|---|---|---|
| General cryptographic hash | SHA-256, SHA-3, BLAKE3 | Fast | No |
| MAC | HMAC-SHA256 | Authenticate integrity | No |
| Password hash | Argon2id, scrypt, bcrypt | Slow and memory-hungry | Yes |
SHA-256 is not "weak" — it is an excellent hash for what it was designed for. The problem is that it is fast, and fast is the worst possible property for a password: a modern GPU tries billions of SHA-256 per second, so an 8-character password hashed with SHA-256 falls in hours, salt or no salt.
Salt solves a different problem and is routinely thought to solve this one. Salt defeats rainbow tables and stops two users with the same password sharing a hash — it does not make cracking one specific password slower. That is the work factor's job.
The parameters to use, per the OWASP Password Storage Cheat Sheet:
| Algorithm | Parameters |
|---|---|
| Argon2id (preferred) | m=19 MiB, t=2, p=1 — or m=47 MiB, t=1, p=1 |
| scrypt | N=2^17, r=8, p=1 |
| bcrypt | cost ≥ 10, and mind the 72-byte limit |
The bcrypt trap is worth knowing: it silently discards every byte past the 72nd. With a long passphrase, or a Vietnamese password with diacritics (2–3 UTF-8 bytes per character), the tail is dropped with no warning.
But the better question than all three rows above is: do you need passwords? Store no password and there is nothing to leak, nothing to hash wrongly, and nobody reusing their password from a site that was already breached. Passkeys (WebAuthn) and OIDC with a provider both remove this problem rather than solving it.
Comments
Commenting needs an account with at least one completed lesson. That condition is what keeps this thread worth reading: every point belongs to someone who can be asked back, and reputation accrues over time.
You can still read every comment below without an account. Signing in brings you back to this exact spot, not to the top of the page.
Loading comments…