bcrypt and htpasswd generator

The bcrypt and htpasswd generator creates a bcrypt hash for a password, builds a line for the .htpasswd file from it, and checks whether a password matches an existing hash.

The hash is created and checked in the browser. Please enable JavaScript.

Everything runs in your browser; nothing is sent or stored.

  • Type a password in the "Password" field, choose a value in the "Cost" list, and click "Create a hash".
  • Under "Prefix", choose $2y$ or $2b$, depending on the prefix your system expects.
  • A progress bar is shown during the calculation. When it finishes, the hashing time is shown in seconds, and the hash appears under "Result".
  • To get a line for the .htpasswd file, enter a username in the "Username for the htpasswd file" field.
  • Copy the result by clicking "Copy the hash" or "Copy the line".
  • bcrypt suits password storage because it is slow on purpose. The hash uses the standard bcrypt format and works with any library that supports bcrypt and with htpasswd files.
  • Under "Check a password against a hash", enter a password and a hash, and click "Check".

Why bcrypt suits password storage

Algorithms such as MD5 and SHA-256 are designed for fast calculation, so an attacker who obtains a database of passwords stored with them can try billions of guesses per second. The bcrypt algorithm is slow on purpose, and the cost parameter sets how slow it is, so you can raise it as computers get faster. A random salt is created for every hash, so the same password gives a different hash each time, and precomputed tables of hashes for common passwords do not help an attacker. Other algorithms designed for password storage are Argon2id and scrypt.

Choosing the cost

The number of rounds is 2 to the power of the cost, so each increase of 1 in the cost doubles the hashing time. We recommend choosing the highest cost at which checking a password on the server still takes only a short time, because the server runs the calculation on every login. The hashing time shown in the tool lets you compare cost values, but the time on the server depends on its hardware. The cost is stored inside the hash, so you can raise it later: many systems create a new hash with the higher cost the next time each user logs in.

The $2a$, $2b$, and $2y$ prefixes

The $2a$ prefix is the original bcrypt prefix, and the $2b$ and $2y$ prefixes were added after bugs were fixed in different implementations, to mark a hash created by a fixed implementation. The $2b$ and $2y$ prefixes mark exactly the same calculation, and they differ only in the label. The line for the .htpasswd file is always written with the $2y$ prefix, as the htpasswd -B command does, even when $2b$ is selected under "Prefix".

Password-protecting a folder with .htpasswd

The .htpasswd file has one line for each user: the username, a colon, and the password hash. On servers that support .htaccess files, a Basic Authentication setting in the .htaccess file points to the .htpasswd file, and the browser asks for a username and password before it opens the folder. We recommend keeping the .htpasswd file outside the public folder of your website and using the protection only on HTTPS addresses, because with Basic Authentication, the password is sent with every request, encoded only in Base64.

The parts of a hash created for the password example with a cost of 12

  • $2y$12$0IOYrtgE7ZAkHtwh8uJCU.nfV6/FvddfMkmFGxi9NcH9MI51R8kj2the full hash, 60 characters long. You can paste it under "Check a password against a hash" together with the password example.
  • $2y$the prefix.
  • 12the cost: 2 to the power of 12, that is, 4,096 rounds of the calculation.
  • 0IOYrtgE7ZAkHtwh8uJCU.the salt, 22 characters long.
  • nfV6/FvddfMkmFGxi9NcH9MI51R8kj2the result of the calculation, 31 characters long.
  • admin:$2y$12$0IOYrtgE7ZAkHtwh8uJCU.nfV6/FvddfMkmFGxi9NcH9MI51R8kj2the line for the .htpasswd file for the user admin.
Did you know?

With Linux hosting, you can password-protect folders on your website.

Linux hosting plans

bcrypt and htpasswd generator FAQ

How is a password checked when each run gives a different hash?

The password is checked with the salt and the cost, which are stored inside the hash itself. During the check, the system reads them from the stored hash, calculates the hash of the entered password with the same values, and compares the results. That is why every hash created for the same password matches it in the check.

Can the password be recovered from a bcrypt hash?

No. The password cannot be calculated from the hash, and the only way to find it is to guess passwords and calculate the hash of each one. The slowness of bcrypt limits the number of guesses, but a common or short password will still be found quickly. Under "Check a password against a hash", you can check a specific password, for example, to make sure the hash was created from the right password.

Does bcrypt use every character of a long password?

No. The bcrypt algorithm uses only the first 72 bytes of the password, and characters beyond that length do not affect the hash. In UTF-8 encoding, a letter outside the English alphabet takes 2 bytes or more, so fewer of these letters are included in the calculation, for example, only the first 36 letters when each letter takes 2 bytes. When the password is longer than 72 bytes, a message about it appears when the hashing or the check finishes.

Which cost should I choose?

The right cost depends on the speed of the server that checks the passwords and on the number of logins to it. The tool selects 12 by default, and you can choose a value from 4 to 14. Low values, such as 4 to 8, are very fast and are suitable mainly for test environments.

Does a hash with the $2y$ prefix work with a library that expects $2b$?

Many libraries accept a hash with either prefix when they check a password. When a library accepts only one of them, you can replace the first four characters of the hash, for example, $2y$ with $2b$, without changing the rest of the hash.

What is the maximum password length for creating a bcrypt hash?

The password can contain up to 256 characters, without the NUL character, and the username for the .htpasswd file can contain up to 64 characters, without a colon. To check a password, the hash must be 60 characters long, with the $2a$, $2b$, or $2y$ prefix and a cost of up to 16. When the hash has a higher cost, the check is not run, because the calculation would take too long.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement