root/guides/password-hashing-bcrypt-argon2
all_guides.md
REFERENCE GUIDE100% Client-Side Verified

Password Hashing Guide: Bcrypt, Argon2 & PBKDF2 Explained

A complete developer's guide to modern password hashing. Learn the differences between Bcrypt, Argon2id, and PBKDF2, and how to choose the right cost factors.

Password hashing is the foundational layer of application security. Whether you are building a new authentication system or auditing an existing one, choosing the right cryptographic algorithm is critical.

In this guide, we break down the most popular password hashing algorithms�Bcrypt, Argon2id, and PBKDF2�and explain how to configure them securely.


Why You Must Hash Passwords

Storing passwords in plaintext (or encrypting them with reversible algorithms like AES) is a catastrophic security risk. If a database is breached, attackers instantly gain access to user credentials.

Hashing is a one-way cryptographic mathematical function. You can verify a password by hashing the user's input and comparing it to the stored hash, but you cannot mathematically reverse the hash to reveal the password.

To protect against brute-force and dictionary attacks, modern password hashes must be:

  1. Slow (Computationally Expensive): To deter attackers from rapidly guessing millions of passwords per second.
  2. Salted: A unique random string added to each password before hashing to neutralize precomputed Rainbow Tables.

1. Bcrypt (The Industry Standard)

Bcrypt is a battle-tested password hashing function based on the Blowfish cipher. It has been the industry standard for over two decades.

How it works

Bcrypt includes a "Cost Factor" (a work factor) that dictates how many iterations the algorithm performs. As computers get faster, you simply increase the cost factor to keep the hash computation slow.

Configuration Best Practices

  • Work Factor (Rounds): A cost factor of 10 to 12 is currently recommended by OWASP. A factor of 12 requires $2^{12}$ (4,096) iterations.
  • Salt: Bcrypt automatically generates and embeds a 128-bit salt in the output hash string.

Example Hash Format: $2b$12$Ex.Random.Salt.String.Here...HashOutputHere (Where $2b$ indicates the algorithm version, 12 is the cost factor, followed by the base64-encoded salt and hash).


2. Argon2id (The Modern Powerhouse)

Argon2 was the winner of the Password Hashing Competition (PHC) in 2015. It is designed to resist both GPU cracking and side-channel attacks.

Why Argon2 is better

Unlike Bcrypt (which only consumes CPU cycles), Argon2 is Memory-Hard. It forces the computer to allocate a massive block of RAM during computation. Attackers using custom ASICs or GPUs to crack hashes in parallel will quickly run out of memory, making it prohibitively expensive to brute-force.

Configuration Best Practices

Argon2id (a hybrid of Argon2i and Argon2d) is the recommended variant.

  • Memory Cost (m): How much RAM to consume (e.g., 64MB).
  • Time Cost (t): Number of CPU iterations (e.g., 3).
  • Parallelism (p): Number of concurrent threads (e.g., 4).

OWASP Recommendation: Use Argon2id with 64MB memory, 3 iterations, and 1 thread for general web applications.


3. PBKDF2 (NIST Approved)

Password-Based Key Derivation Function 2 (PBKDF2) is an older, standardized algorithm approved by NIST (National Institute of Standards and Technology) and FIPS.

When to use it

PBKDF2 is widely supported in enterprise environments and legacy systems. It relies on standard cryptographic hash functions like SHA-256 or SHA-512. However, it is not memory-hard, making it more vulnerable to GPU acceleration than Argon2.

Configuration Best Practices

  • Hash Function: Always use SHA-256 or SHA-512. Do not use MD5 or SHA-1.
  • Iterations: OWASP recommends a minimum of 600,000 iterations for PBKDF2-HMAC-SHA256 to counter modern hardware speeds.

Try it out

Understanding these parameters can be abstract. Use our Password Hash & Verifier tool to generate Bcrypt, Argon2, and PBKDF2 hashes locally in your browser. You can tweak the cost factors in real-time to see how they impact execution time and output length, or securely verify a candidate password against an existing database hash string.

Live Tool: Bcrypt / Argon2 / PBKDF2 Password Hash Verifier & Generator

Client-Side

Generate and verify passwords against Bcrypt ($2a/$2b), Argon2id, and PBKDF2 hashes with cost factor controls.

Launch Tool