Bcrypt

Hash and compare text string using bcrypt.

loading Bcrypt
About this tool

What is bcrypt?

bcrypt is a password hashing function designed in 1999, built on the Blowfish cipher. Unlike SHA-256 or MD5, which are made to be fast, bcrypt is made to be slow on purpose, and you control how slow with a setting called the cost. That is exactly what you want for passwords: a login check can afford a fraction of a second, but an attacker who stole your database has to pay that price for every single guess.

A bcrypt hash is a self-contained string of 60 characters. Take $2b$10$abcdefghijklmnopqrstuu5Lo0g67CiD3M4RpN1BmBb4Crp5w7dbK: the $2b$ is the version, 10 is the cost, the next 22 characters are the random salt and the remaining 31 are the hash itself. Because the salt and the cost travel inside the string, you only store one column in the database, and comparing a login attempt needs nothing else. A new random salt is created for every hash, so two users with the same password get different hashes.

This bcrypt generator and checker hashes a password with the cost and version you pick, and compares a password against an existing hash to answer Yes or No. It runs entirely in your browser, in background workers so the page never freezes, which means the passwords you type are not sent anywhere. For other password hashes (Argon2id, PBKDF2) and plain digests, the hash generator covers them; to see how a password stands against guessing, use the password strength analyser.

How to generate a bcrypt hash

  1. Type the password in the Password box of the Hash card. The page opens with my secret password already hashed, so you can see the format at once.
  2. Choose the Cost (rounds) from 4 to 16. The default is 10. A hint under the field estimates how long that cost takes in your browser, and after each run the page shows how long the last hash took. Each extra round doubles the work.
  3. Pick the Hash version: $2b$ is the current one; $2a$ is older but still read by many libraries.
  4. Read the result under the options: it is recomputed as you type or change a setting, with a progress bar while the worker runs. Press Copy hash to take it.
  5. To verify a login, go to the card Check a password against a hash. Type the password, paste the hash (or press Use the hash above, which fills in both fields) and read Do they match?: Yes or No.

Examples

Anatomy of a hash

Hashing password at cost 10 with a fixed salt (the page uses a random one, so yours will differ) gives:

$2b$10$abcdefghijklmnopqrstuu5Lo0g67CiD3M4RpN1BmBb4Crp5w7dbK

Checking password against it answers Yes. Checking Password with a capital P answers No: bcrypt is case sensitive and one character changes everything.

Same password, different hash

Hash maria-silva-2024 twice and you get two different strings, because each run draws a new salt. Both pass the check, since the salt is inside the hash. This is why you never compare bcrypt hashes with ==: you always call a compare function.

Raising the cost

The same password at cost 12 starts with $2b$12$. The hash is still 60 characters, but producing it takes about four times as long as at cost 10. Pick the highest cost your login can bear without users noticing.

The 72-byte limit

bcrypt reads only the first 72 bytes of the password. Two passwords that share their first 72 bytes get the same result, so a password of 72 a followed by XYZ matches one followed by QQQ. The page warns you when your text is longer. Accented letters count 2 bytes and emoji 4, so a long passphrase in Portuguese can hit the limit sooner than you expect.

Common errors and how to fix them

  • "This is not a bcrypt hash. It has 60 characters and starts with $2a$, $2b$ or $2y$ followed by the cost": the pasted hash was cut, has a space or a line break, or comes from another algorithm. Copy the full 60 characters.
  • "The cost must be a whole number from 4 to 16.": type an integer in that range. Costs below 10 are too cheap for production.
  • "This took more than ... seconds and was stopped. Lower the cost.": a high cost multiplies the time. Try a lower value, or run the hash on your server where it belongs.
  • "bcrypt only reads the first 72 bytes of a password": a warning, not an error. Shorten the password or pre-hash it in your application.
  • It says No but the password is right: look for a trailing space or a different keyboard layout. Hashes saved with $2y$ by PHP are accepted.

Frequently asked questions

Is bcrypt still safe to use?

Yes. bcrypt remains a sound choice for storing passwords when the cost is high enough, and it is supported by every major language. Newer designs such as Argon2id, which is also available in the hash generator, add memory hardness, but a well-tuned bcrypt is not considered broken.

Can a bcrypt hash be decrypted?

No. It is a one-way function, so there is nothing to decrypt. The only way to find the password is to guess it and hash the guess, which is why the cost matters and why weak passwords still fall.

What cost should I use?

Choose the highest value that keeps your login under an acceptable delay, measured on your own servers. Ten is the long-standing default and a reasonable floor; many teams now use 12 or more. The estimate on this page shows the time in a browser, which is only a guide.

What is the difference between bcrypt and encryption?

Encryption can be reversed with a key; hashing cannot. If you need to read the data back, see the encrypt and decrypt tool instead.

Hash and verify bcrypt in code

JavaScript

import bcrypt from 'bcryptjs';

const hash = await bcrypt.hash('password', 10);
console.log(await bcrypt.compare('password', hash)); // true

Python

import bcrypt

hashed = bcrypt.hashpw(b'password', bcrypt.gensalt(rounds=10))
print(bcrypt.checkpw(b'password', hashed))  # True

Go

// import "golang.org/x/crypto/bcrypt"
hash, _ := bcrypt.GenerateFromPassword([]byte("password"), 10)
err := bcrypt.CompareHashAndPassword(hash, []byte("password")) // nil when it matches

Bash

htpasswd -nbBC 10 user 'password'
Report a problem