Bcrypt Explained: How Password Hashing Actually Works (And How to Test It Safely)
Somewhere right now, a database is storing passwords in plain text. Or with MD5. Or — my personal favorite — with SHA-256, because "it's a hash, isn't it?" It's a hash. It's also the wrong tool, and the difference matte
Somewhere right now, a database is storing passwords in plain text. Or with MD5. Or — my personal favorite — with SHA-256, because "it's a hash, isn't it?"
It's a hash. It's also the wrong tool, and the difference matters the day that database leaks. Let's talk about bcrypt, the algorithm that has been quietly doing this job correctly for over 25 years.
🛠️ Free Tool: Bcrypt Hash Generator & Verifier — WebToolsHub — generate bcrypt hashes and verify passwords against them, right in your browser. Useful for testing auth flows without touching production data.
Why "Fast" Is a Bug in Password Hashing
SHA-256 was designed to be fast. An attacker with a modern GPU can try billions of SHA-256 hashes per second. Your users' passwords — most of which are embarrassingly predictable — fall in an afternoon.
Bcrypt is deliberately slow, and it has a dial for it: the cost factor. Cost 12 means 2¹² rounds of work. Each login costs your server a fraction of a second — invisible to a user signing in once, devastating to an attacker trying a billion guesses.
The Salt Is Built In
A bcrypt hash looks like this:
$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewdBPj4J/HS.iK2W
That string contains everything: the algorithm version (2b), the cost (12), the salt (next 22 characters), and the hash itself. No separate salt column, no extra bookkeeping — and because every password gets a unique random salt, two users with the same password have completely different hashes, and rainbow tables are useless.
Rules That Keep You Out of Trouble
- Never roll your own. Use your framework's bcrypt (or argon2) library. The algorithm is only safe when the implementation is boring and battle-tested.
- Cost 10–12 is the usual sweet spot. Higher is slower for attackers and for your login endpoint. Benchmark on your own hardware.
- Bcrypt truncates at 72 bytes. Long passphrases get silently cut. Know it before your security audit finds it.
- Hashing is not encryption. You can never "decrypt" a bcrypt hash — verification means hashing the attempt with the stored salt and comparing. That's the entire point.
Testing Without Regret
When you're debugging an auth flow — "why won't this test user log in?" — you often need to check whether a password matches a stored hash. That's what the bcrypt verifier is for: paste the hash, type the candidate password, get a yes/no — in your browser, not on some random server you're trusting with credentials.
Store passwords like you'll be breached one day. Because the statistics are not on your side.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.