About bcrypt hash generator
bcrypt is a deliberately slow function for storing passwords. It adds a random salt and a cost factor, so identical passwords give different hashes and guessing is expensive.
Choosing the cost
- The cost is a power of two: each extra step doubles the work.
- A value of 10 to 12 is typical today; pick the highest value your server can afford without slowing logins.
- Raise the cost over time as computers get faster.
Limits
bcrypt only uses the first 72 bytes of a password. For new projects Argon2id is also a good choice.
Verify mode
You can check a password against an existing bcrypt hash to confirm that it matches.
A worked example
A bcrypt hash looks like $2b$12$ followed by a 22-character salt and a 31-character hash, 60 characters in all. The 12 is the cost. Hashing the same password twice gives different results because each hash has a new random salt, and the check function still verifies both.
Tips
- Measure how long hashing takes on your server and aim for roughly a quarter second.
- Never truncate or pre-hash passwords unless you understand the effects.
- Re-hash with a higher cost the next time a user logs in.
