Bcrypt Hash Generator
Generate secure bcrypt password hashes for your applications. Industry-standard hashing algorithm with configurable cost factor for maximum security.
π Security Note:
Never store passwords in plain text! Always use bcrypt or similar algorithms to hash passwords before storing them in your database. This tool generates hashes in your browser for security.
What is Bcrypt?
Bcrypt is a password hashing function designed by Niels Provos and David Mazières in 1999. It's based on the Blowfish cipher and is specifically designed to be slow and computationally expensive, making it resistant to brute-force attacks. Bcrypt automatically generates a salt and incorporates it into the hash, ensuring that the same password will produce different hashes.
Why Use Bcrypt for Password Hashing?
- Adaptive Cost Factor: Can be made slower as computers get faster by increasing the cost factor
- Built-in Salt: Automatically generates and includes a random salt in the hash
- One-Way Function: Computationally infeasible to reverse the hash back to the password
- Industry Standard: Widely adopted and recommended by security experts
- Rainbow Table Resistant: Salt makes rainbow table attacks impractical
- Brute Force Resistant: Slow by design to prevent rapid password guessing
Understanding Cost Factor (Salt Rounds)
The cost factor (also called work factor or salt rounds) determines how computationally expensive the hashing process is. The actual number of iterations is 2^cost. For example:
- Cost 10: 2^10 = 1,024 iterations (recommended for most applications)
- Cost 12: 2^12 = 4,096 iterations (high security applications)
- Cost 14: 2^14 = 16,384 iterations (maximum security, slower)
Higher cost factors make brute-force attacks exponentially more difficult but also increase the time required to hash passwords. Choose a balance between security and user experience. Cost 10-12 is recommended for most web applications.
Bcrypt Hash Format
A bcrypt hash follows this format:
$2a$10$N9qo8uLOickgx2ZMRZoMye.IFdZx1p4L9X7lSJhR6.kMdKgQfQ.JC β β β β β β β ββ Hash (31 chars) β β ββββββββββββββββββββββββ Salt (22 chars) β βββββββββββββββββββββββββββββ Cost factor ββββββββββββββββββββββββββββββββ Algorithm version
When to Use Bcrypt
- User Authentication: Hash user passwords before storing in database
- API Keys: Hash API keys for secure storage
- Sensitive Data: Hash any sensitive credentials or secrets
- Password Reset Tokens: Hash temporary tokens
- Session Tokens: Hash session identifiers for added security
Implementation Examples
Node.js (bcrypt)
const bcrypt = require('bcrypt');
const saltRounds = 10;
// Hash password
const hash = await bcrypt.hash('password', saltRounds);
// Verify password
const match = await bcrypt.compare('password', hash);
PHP (password_hash)
// Hash password
$hash = password_hash('password', PASSWORD_BCRYPT, ['cost' => 10]);
// Verify password
$match = password_verify('password', $hash);
Python (bcrypt)
import bcrypt # Hash password password = b'password' salt = bcrypt.gensalt(rounds=10) hash = bcrypt.hashpw(password, salt) # Verify password match = bcrypt.checkpw(password, hash)
Java (BCrypt)
import org.mindrot.jbcrypt.BCrypt;
// Hash password
String hash = BCrypt.hashpw("password", BCrypt.gensalt(10));
// Verify password
boolean match = BCrypt.checkpw("password", hash);
Best Practices
- Use cost factor between 10-12 for web applications
- Never store passwords in plain text
- Always use the verify/compare function to check passwords
- Don't try to decrypt bcrypt hashes - they're one-way
- Let bcrypt generate the salt automatically
- Increase cost factor over time as hardware improves
- Test hash generation time in your production environment
- Consider using bcrypt for API keys and tokens too
Frequently Asked Questions
Can I decrypt a bcrypt hash?
No, bcrypt is a one-way hashing function. It's designed to be impossible to reverse. To verify a password, you hash the input and compare it to the stored hash.
What cost factor should I use?
Cost 10 is recommended for most applications. Use 12+ for high-security applications where slower hash generation is acceptable.
Why does the same password produce different hashes?
Bcrypt automatically generates a random salt for each hash. This is a security feature that prevents rainbow table attacks. The salt is stored as part of the hash string.
Is bcrypt better than SHA-256?
For password hashing, yes. Bcrypt is designed specifically for passwords with adaptive cost, while SHA-256 is fast and not ideal for passwords. Use bcrypt for passwords and SHA for checksums/integrity.