Generate Bcrypt Hash
Bcrypt is a password hashing function designed to be computationally expensive, making it resistant to brute-force attacks.
About Bcrypt Hashing
Bcrypt is a password hashing function based on the Blowfish cipher. It incorporates a salt to protect against rainbow table attacks and is intentionally slow to hinder brute-force attempts.
How Bcrypt Works
Bcrypt uses an adaptive hash algorithm that:
- Generates a random salt for each password
- Applies the Blowfish encryption algorithm repeatedly (2^cost times)
- Produces a 60-character hash string containing algorithm version, cost factor, salt, and hash
Cost Factor Explained
The cost factor (work factor) determines how computationally intensive the hashing process is:
- 4-6: Very fast (not recommended for production)
- 10-12: Good balance between security and performance (default)
- 14+: Very secure but slow to generate
As computers get faster, you should increase the cost factor to maintain security.
Why Use Bcrypt?
- Built-in Salt: Automatically generates and stores a unique salt for each hash
- Adaptive: Can increase work factor as hardware improves
- Proven Security: Widely used and vetted by security experts
- Slow by Design: Resistant to brute-force and rainbow table attacks
Security Best Practices
- Always use a cost factor of 10 or higher in production
- Never store plain text passwords
- Consider using pepper (application-wide secret) in addition to bcrypt
- Use HTTPS for all password transmissions
- Implement rate limiting on authentication attempts
Verifying Bcrypt Hashes
To verify a password against a bcrypt hash, you need to:
- Extract the salt and cost factor from the stored hash
- Hash the candidate password using the same parameters
- Compare the resulting hash with the stored hash
Most programming languages have bcrypt libraries that handle this verification process automatically.