1. Home
  2. Bcrypt Generator

Bcrypt Generator

Hash a password with bcrypt in the exact format PHP's password_hash() produces, or check a password against an existing hash. Everything runs in your browser.

Generate a hash

Your hash appears here.

Verify a password

Same as password_verify($password, $hash) in PHP. Accepts $2y$, $2b$ and $2a$ hashes.

Hashing runs locally with the bcryptjs library. Nothing you type is sent anywhere.

How to use this bcrypt generator

  1. Type the password you want to hash. Spaces and Unicode are kept exactly as typed.
  2. Choose a cost. The default of 12 matches PHP 8.4 and newer. The label shows how long one hash took in your browser, which is a rough guide to your server.
  3. Press Generate. Copy the hash into a database seed, a test fixture or a config file. Every press gives a new hash because the salt is random.
  4. To check a hash, paste it on the right with a password. You get a clear match or no-match answer, just like password_verify().

Anatomy of a bcrypt hash

A bcrypt hash is always 60 characters and carries everything needed to verify it later. Take $2y$12$R9h/cIPz0gi.URNNX3kh2OPST9/PgBkqquzi.Ss7KIUgO2t0jWMUW:

  • $2y$ is the algorithm identifier: bcrypt, with PHP's name for the fixed version.
  • 12$ is the cost. The algorithm runs 212 = 4,096 rounds of its expensive key setup.
  • The next 22 characters are the salt, encoded in bcrypt's own base64 alphabet.
  • The last 31 characters are the hash itself.

Because salt and cost live inside the string, you store the whole hash in one column, usually VARCHAR(255) so a future algorithm with longer output still fits.

Hashing passwords in PHP

PHP has had a complete password API since 5.5. You never need to call crypt() or build salts yourself:

$hash = password_hash($password, PASSWORD_DEFAULT);

if (password_verify($input, $hash)) {
    // correct password
    if (password_needs_rehash($hash, PASSWORD_DEFAULT)) {
        $hash = password_hash($input, PASSWORD_DEFAULT); // store the upgraded hash
    }
}

PASSWORD_DEFAULT is bcrypt today, and PHP may switch it to a stronger algorithm in a future release, which is why the column should be wider than 60 characters. password_needs_rehash() lets you raise the cost over time: when a user logs in successfully, rehash with the new settings and save it. To set the cost explicitly, pass ['cost' => 12] as the third argument. You can try these functions directly in the PHP Sandbox.

Bcrypt or Argon2?

Both are good choices and far better than MD5, SHA-1 or plain SHA-256, which are fast by design and therefore easy to brute-force. Argon2id, available in PHP as PASSWORD_ARGON2ID when PHP is built with libargon2 or libsodium, is memory-hard, which makes attacks with graphics cards more expensive. Bcrypt is supported everywhere, is the PHP default and remains a safe choice when the cost is set sensibly. Moving from one to the other is easy, since password_verify() understands both and password_needs_rehash() tells you when to upgrade.

Common problems

  • Verify always fails: the hash was cut off. Check that the database column holds all 60 characters and that no framework trimmed or escaped the $ signs. In .env files and shell commands, wrap the hash in single quotes.
  • Hash from another language does not verify: make sure it is really bcrypt and starts with $2. Hashes from Node's bcrypt ($2b$) work in PHP without changes.
  • Logins are slow: the cost is too high for your server. Lower it by one and let password_needs_rehash() migrate users as they log in.

More PHP tools

Frequently asked questions

Is it safe to type a real password here?

The hash is computed by JavaScript in your browser and nothing is sent to our server, which you can confirm in your browser's network panel. Even so, the safest habit is to generate hashes for real accounts inside your own application, with password_hash(), and use this tool for testing, seeding databases and checking existing hashes.

What is the difference between $2y$, $2b$ and $2a$?

They are the same bcrypt algorithm. $2a$ is the original prefix. $2y$ was introduced by PHP in 5.3.7 after a bug in another implementation, and $2b$ is the name OpenBSD later chose for the same fix. PHP's password_verify() accepts all three, and Node, Python and Go libraries generally accept them too.

Which cost should I use?

Pick the highest cost that keeps a login under about a quarter of a second on your server. PHP 8.4 raised the default from 10 to 12, which is a good starting point today. Each step up doubles the work, so cost 13 takes twice as long as 12, for you and for an attacker.

Why does the same password give a different hash every time?

Each hash contains a fresh random 22-character salt, so two users with the same password get different hashes. That is intended. To check a password, do not hash it again and compare strings; use password_verify(), which reads the salt and cost from the stored hash.

Can a bcrypt hash be decrypted?

No. Bcrypt is a one-way function. The only way to recover a password is to guess candidates and hash each one, which the cost factor makes slow on purpose. Sites that claim to “decrypt bcrypt” only look up hashes of common passwords.

Does bcrypt have a password length limit?

Yes. Bcrypt only uses the first 72 bytes of the password. Characters beyond that are ignored, and multi-byte characters such as emoji use up the limit faster. If you need longer passphrases, consider Argon2id through PASSWORD_ARGON2ID.