Bcrypt

Hash and verify passwords using bcrypt algorithm

Hash password

Hash updates when you change password or rounds

Compare password

Result updates when you change password or hash

bcrypt vs SHA-256: choosing the right hash

TL;DR

What is Bcrypt?

bcrypt is a password-hashing function designed by Niels Provos and David Mazières, published in 1999. Unlike general-purpose hash functions like SHA-256, bcrypt is intentionally slow: a configurable cost factor controls how many iterations are performed, making brute-force attacks computationally expensive even as hardware improves.

How it works

bcrypt generates a random 128-bit salt, then runs the Blowfish cipher key schedule 2^cost times. The output is a 60-character string that encodes the algorithm version, cost factor, salt, and hash together. Because the salt and cost are embedded in the output, verifying a password only requires the original plaintext and the stored hash.

Common use cases

  • Password storage: hash user passwords before storing them so a database breach does not expose plaintext credentials
  • Password verification: compare a login attempt against a stored hash without ever storing the password itself
  • Adjustable security: increase the cost factor over time as hardware gets faster, without changing the algorithm

Frequently asked questions

What cost factor should I use?

Pick a cost that makes hashing take 100-300ms on your hardware. Cost 10 to 12 is common for web applications. Higher is more secure but increases login response time. Re-evaluate every few years as hardware gets faster.

Can I use bcrypt for data other than passwords?

No. bcrypt truncates input at 72 bytes and is too slow for general hashing. Use SHA-256 or SHA-512 for checksums, file integrity, or any non-secret data where speed matters.

Is bcrypt still recommended?

Yes, for passwords. Argon2 (winner of the 2015 Password Hashing Competition) is the modern alternative and is preferred for new systems. bcrypt remains secure and is still widely supported by all major languages and frameworks.

What does the $2b$ prefix mean?

$2b$ identifies the bcrypt variant. It is the current standard, introduced to fix a bug in the earlier $2a$ implementation on certain platforms. If you see $2a$ in stored hashes, they are likely still valid but were generated by an older library version.

See also

  • Hash text: for non-password hashing such as checksums and fingerprints, SHA-256 or SHA-512 are the right tools: they are fast where bcrypt is intentionally slow
  • Password strength analyser: check a password's entropy before hashing it: a weak password is still easy to crack even with bcrypt if the attacker can narrow the search space
  • Token generator: generate a cryptographically random token as an alternative to user-chosen passwords for API keys and session secrets