Home / Knowledge hub / bcrypt
Knowledge hub
bcrypt
A deliberately slow password hashing function with a built-in salt.
What it means
bcrypt is a password hashing function designed in 1999 by Niels Provos and David Mazières, built on the Blowfish cipher. It is deliberately slow, and you can make it slower as computers get faster by raising a setting called the cost factor. It generates a random salt for each password and stores it inside the output.
The result is a single text string, commonly starting $2b$, followed by the cost, the salt and the hash. Verifying a password means reading the cost and salt from that string, hashing the attempt the same way, and comparing. Each increase of one in the cost doubles the work.
Why it matters
A fast hash lets an attacker with a stolen database try enormous numbers of guesses. bcrypt slows each guess, and the built-in salt stops one guess being checked against every account at once or against a precomputed table. A weak password still falls quickly, but a strong one gets a real defence.
It has been used widely for decades and is supported in nearly every language, so it is a safe, familiar choice. It is not memory-hard, though, so specialised hardware can speed attacks more than for Argon2, which is why current guidance prefers the newer design where available.
How it shows up
You will see it in the user table as 60-character strings. OWASP suggests a work factor of at least 10 and more if your servers allow, and says to raise it over time. Check the delay at login: it should be noticeable to an attacker but not annoying to a user, typically a fraction of a second.
The known trap is the 72-byte input limit. Longer passwords are cut off or, in some libraries, rejected, so two long passwords sharing their first 72 bytes can look identical. Other mistakes: leaving the cost at an old default, hashing the password with a fast hash first without care, and failing to upgrade old hashes at the next sign-in. See also key derivation functions.
Questions people ask
bcrypt, answered
Does bcrypt need a separate salt?
No. It generates a random salt for every password and stores it inside the output string, so you store one value. Do not add your own unless a library requires it.
Never reuse a salt.
What cost factor should I use?
OWASP recommends a work factor of at least 10. Choose the highest value your login path can bear, and raise it as hardware gets faster. Measure on your own servers.
Review the number each year.
What is the 72-byte limit?
bcrypt reads only the first 72 bytes of a password. Anything longer is ignored or rejected depending on the library. Multi-byte characters use more than one byte each.
Check what your library does.
Is bcrypt still safe to use?
Yes, with a sensible cost factor, and it is a widely supported option. OWASP lists Argon2id first and bcrypt as acceptable for legacy systems or where Argon2 is not available.
Do not rewrite a working system in a hurry.
How do I migrate from a weaker hash to bcrypt?
Hash the user’s password with bcrypt the next time they sign in successfully, then replace the old hash. Wrapping existing hashes in bcrypt is another way to protect users who never return.
Mark each record with its algorithm.
Sources
Where this comes from
Related
Terms that sit next to this one
Argon2
A modern password hashing function that is slow and memory-hungry on purpose.
scrypt
A password hashing function that needs a lot of memory, which slows cracking hardware.
PBKDF2
An older password hashing method that repeats a hash many thousands of times.
Salt
Random data added to each password before hashing so identical passwords differ.
Key derivation function (KDF)
A function that turns a password or secret into a strong, fixed-size key.
Is your cost factor still enough?
How passwords are stored is something white-box testing can check directly. Cyberlop reads your code while testing the running app, so a finding can point to the file and line. Ask us to run it on one of your applications.
Or start with a $199 pilot on one application: thirty days, success criteria agreed before day one, credited against the annual if you convert.