bcrypt Generator · Tutorial

How to check a password against a bcrypt hash

6 min readintermediateUpdated

A user, or a test account, can't log in, and you want to know whether the stored hash actually matches the password you expect. bcrypt hashes can't be reversed, but they can be checked. This tutorial checks a password against a hash, explains what the parts of the hash mean, and shows how to create a replacement hash.

What you need

  • The bcrypt Generator
  • The stored hash (from your database or seed file) and the password you expect (the Try it button loads a matching pair)

Steps

  1. Paste the stored hash

    Copy the hash from your database into bcrypt hash in the right-hand panel. As soon as it's pasted, the tool reads it. The sample is version $2b$, cost 10, which is 1,024 rounds.

    $2b$10$rva4HbxDR18SFqyrLw5yduioNJG5omFqUqIBCp38SRYcYlJzy5fyS
  2. Enter the expected password

    Type the password you expect in Password. The sample uses maple-otter-violin.

  3. Check

    Press Check. A green badge means the password matches. A red badge means it doesn't. Then the problem is the password, or the hash was created differently than you think.

  4. Look for common causes

    If it doesn't match, check for surrounding spaces in the password, a hash cut short when copied (it must be exactly 60 characters), or an application that adds a "pepper" or pre-hashes passwords before bcrypt.

  5. Create a replacement hash if needed

    To reset a test account, type a new password in the left panel, choose cost 10–12 and press Generate hash. Store the new hash in the database in place of the old one.

Try it yourself

Opens the bcrypt Generator with this tutorial's sample loaded.

Try it now

Common mistakes

Trying to "decrypt" the hash
bcrypt is one-way. You can only check guesses against it, which is exactly why it's safe.
Comparing hashes directly
Two hashes of the same password are different because of the random salt, so comparing hash strings never works. Always use the library's compare or verify function.
Truncated hashes in the database
If a column is shorter than 60 characters, hashes are cut off and never match. Use a column of at least 60 characters.

Next steps

Go back to the bcrypt Generator, or keep going with one of these:

FAQ

Is it safe to check real users' passwords here?

The check runs entirely in your browser. Still, avoid handling real users' passwords at all if you can. Ask them to reset instead.