Bcrypt Generator

Generate secure bcrypt password hashes for safe password storage.

0 of 0 ratings

Bcrypt Generator: Create Secure Password Hashes

Bcrypt is a password-hashing function designed by Niels Provos and David Mazières, based on the Blowfish cipher. It is specifically designed for password storage and is considered one of the best algorithms for this purpose. A bcrypt generator takes a password and produces a bcrypt hash that can be safely stored in a database. This tool makes it easy to generate bcrypt hashes for testing, development, and understanding how password hashing works.

Why Bcrypt Is Recommended for Passwords

Unlike general-purpose hash functions like MD5 or SHA-256, bcrypt is intentionally slow. This slowness makes brute-force attacks much harder. Key features include:

  • Adaptive cost: Bcrypt includes a cost factor that determines how many iterations are performed. As hardware gets faster, the cost can be increased to maintain security. This future-proofs bcrypt against advances in computing power.
  • Salt: Bcrypt automatically generates a random salt for each password, preventing rainbow table attacks and ensuring that identical passwords produce different hashes.
  • Resistance to GPU attacks: Bcrypt is memory-intensive, making it less efficient to crack on GPUs compared to algorithms like PBKDF2.
  • Widely supported: Bcrypt is available in virtually every programming language and framework, making it easy to implement.

How Bcrypt Works

Bcrypt uses the Blowfish cipher with a modified key schedule. It takes the password, a salt, and a cost factor as input. The output is a 60-character string that includes the algorithm identifier, cost, salt, and hash. For example:

$2y$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy

Breaking it down:

  • $2y$ — The algorithm identifier and version.
  • 10 — The cost factor (2^10 = 1024 iterations).
  • N9qo8uLOickgx2ZMRZoMye — The salt (22 characters, Base64-encoded).
  • IjZAgcfl7p92ldGxad68LJZdL17lhWy — The hash (31 characters, Base64-encoded).

Why Not Use MD5 or SHA-256 for Passwords?

MD5, SHA-1, and SHA-256 are designed to be fast. This speed is a liability for password hashing — attackers can compute billions of hashes per second using modern hardware. Bcrypt is deliberately slow, making such attacks impractical. Additionally, bcrypt includes a salt by default, whereas MD5 and SHA-256 do not. Using a fast hash for passwords is a serious security vulnerability.

Salt and Its Importance

A salt is random data added to the password before hashing. It ensures that even if two users have the same password, their hashes are different. This prevents attackers from using precomputed tables (rainbow tables) and from cracking multiple passwords simultaneously. Bcrypt generates a unique salt for each hash and stores it as part of the hash string, so no separate salt storage is needed.

Choosing a Cost Factor

The cost factor should be chosen based on the hardware and the desired security level. A common recommendation is to use a cost that results in about 100–300 milliseconds per hash on the server. This makes brute-force attacks slow while keeping authentication fast enough for users. As hardware improves, the cost should be increased. Common values are 10, 11, or 12 for web applications.

Practical Example

Hashing the password mysecretpassword with bcrypt and a cost of 10 might produce:

$2y$10$bJ8QZ9vXK7pL5nR2sT4uOeYcW1mX3zA6dF0gH9iJ8kL7mN6oP5qR

The salt and cost are embedded in the string, so verification is straightforward. When a user logs in, you hash the entered password with the stored salt and cost, then compare the result to the stored hash.

Bcrypt in Different Languages

  • PHP: password_hash($password, PASSWORD_BCRYPT) and password_verify($password, $hash).
  • Python: The bcrypt library or passlib.
  • Node.js: The bcrypt or bcryptjs packages.
  • Ruby: The bcrypt gem.
  • Java: The BCrypt class from Spring Security or jBCrypt.

Conclusion

Bcrypt is a robust and widely recommended algorithm for password hashing. Its adaptive cost, built-in salt, and resistance to GPU attacks make it far superior to general-purpose hash functions for password storage. When building any application that stores user passwords, bcrypt should be your first choice. Use this generator to create bcrypt hashes for testing and development, and always use bcrypt in your production applications.

Popular tools