Password Hashing with bcrypt
What you'll learn: How bcrypt's adaptive hashing mechanism defends passwords against increasingly powerful brute-force attacks over time.
Why bcrypt Exists
You've learned about salts defending against rainbow tables, but there's another threat: raw computational speed. As hardware improves, attackers can test billions of password guesses per second against simple hash functions like SHA-256. bcrypt solves this by being intentionally slow.
The Core Idea: Adaptive Work Factor
bcrypt includes a cost factor (also called "work factor") that determines how many computational rounds the algorithm performs. Think of it like adding speed bumps to a road—each bump slows down traffic just a little, but multiply them and the journey takes significantly longer.
The work factor is typically expressed as a number between 4 and 31, representing 2^n iterations. A work factor of 10 means 2^10 = 1,024 rounds; 12 means 4,096 rounds. Each increment doubles the computation time.
Adaptive Over Time
As computers get faster, you simply increase the work factor. A hash created with cost 10 in 2015 can be migrated to cost 12 in 2025 when users next log in. The algorithm adapts to future hardware without changing the underlying cryptographic approach.
Implementation Best Practices
- Choose an appropriate cost: Aim for 250ms-500ms hashing time on your server. Too low = vulnerable; too high = denial-of-service risk.
- Store cost with the hash: bcrypt hashes include the cost factor in the output string, so verification automatically uses the correct setting.
- Increase periodically: Review and increment the cost factor every few years as hardware advances.
Key Takeaway: bcrypt's adaptive work factor makes password hashing computationally expensive for attackers, and its adjustable difficulty ensures protection scales with future hardware improvements.