Crypto & Security · Ch. 6
How to Store Passwords: Salting, Slow Hashing, and bcrypt's Three Lines of Defense
WebTool Team · Published 2026-09-08 · Passwords / bcrypt / Security / Backend
The correct answer for password storage: a "slow hash with automatic salting" algorithm like bcrypt, scrypt, or argon2. Any fast general-purpose hash (the MD5/SHA family) fails the test — even with a salt. Use our random password generator to create high-strength passwords.
The three lines of defense
Defense one: never store plaintext. Database breaches are a matter of probability, not hypotheticals. Plaintext storage leaks every user's password directly — and because people reuse passwords across sites, the blast radius multiplies.
Defense two: add hashing. Hashes are irreversible, but general-purpose hashes are far too fast — a consumer GPU can compute tens of billions of MD5 hashes per second, so a dictionary of common passwords plus brute force finishes quickly.
Defense three: slow hashing + salt.
- Salt: hash each password together with a random value so identical passwords produce different hashes, defeating rainbow tables and batch cracking. The salt doesn't need secrecy — store it alongside the hash.
- Slowness (work factor): bcrypt's cost parameter stretches each computation to a controlled duration (e.g. 100ms). Users won't notice at login, but an attacker's enumeration cost is amplified a hundred-million-fold. As hardware improves, just raise the cost.
Comparison table
| Approach | Resists rainbow tables | Resists GPU brute force | Verdict |
|---|---|---|---|
| Plaintext | ❌ | ❌ | Forbidden |
| MD5(password) | ❌ | ❌ | Forbidden |
| SHA-256(salt+password) | ✅ | ❌ (too fast) | Inadequate |
| bcrypt / argon2 | ✅ | ✅ | The standard answer |
The complete pipeline
- Transport relies on HTTPS — don't hash on the client before sending; that turns the hash itself into a "password equivalent."
- Leave room in the storage column: bcrypt output is a fixed 60 characters, but argon2's PHC string is longer — VARCHAR(255) is a safe choice.
- Don't distinguish "user not found" from "wrong password" in login errors, or attackers can enumerate valid accounts.
- Add CAPTCHAs and rate limiting to block online credential stuffing.
Last updated: 2026-09-08