Password Hashing: Argon2id vs bcrypt vs scrypt vs PBKDF2

  • Cybersecurity
  • Passwords
  • Beginner friendly
  • 12 min read

Password hashing is how a website stores your password without actually keeping it: it saves a one-way fingerprint that can check a login but cannot be turned back into the password. The algorithm you pick decides how long a thief needs to crack those fingerprints after a data breach. This guide compares the six names you will meet most often, MD5, SHA-256, PBKDF2, bcrypt, scrypt and Argon2id, explains why the fast ones fail, and shows tested code for the right ones.

Last updated: December 2026

In short

  • Use Argon2id for new systems. If it is not available, use scrypt. Keep bcrypt in systems that already have it; use PBKDF2 when FIPS-140 rules apply.
  • Never use MD5 or SHA-256 alone for passwords. They are built to be fast, so attackers can test billions of guesses per second.
  • Every password gets its own random salt, and the hashing must be slow on purpose. Modern libraries handle both for you.
How password hashing works: sign up, log in, and what a thief sees after stealing the database
Password hashing in three steps: signing up, logging in, and what happens when the database is stolen. Tap the picture to see it full size.

What Is Password Hashing?

A hash function turns any input into a fixed-length string. The same input always gives the same output, and there is no key that turns the output back into the input. That makes it different from encryption, which is built to be reversed by whoever holds the key.

When you sign up, the site hashes your password and saves only the result. When you log in, it hashes what you typed and compares the two. If they match, you are in. The site never needs to know your real password, and a stolen database holds only hashes.

An attacker with the stolen hashes can still guess. They hash “123456”, “password”, every word in a dictionary and every leaked password from older breaches, and compare. How long that takes depends on how expensive each guess is, and the password hashing algorithm sets that price.

Why Fast Hashes Like MD5 and SHA-256 Fail

MD5 and SHA-256 were designed to check files and messages quickly. Speed is a feature there, and a disaster for passwords. On our test PC, a plain Python script managed about 1.6 million MD5 hashes and 1.8 million SHA-256 hashes per second on one CPU core. Cracking tools on a gaming graphics card go far beyond that: user benchmarks on the hashcat forum show more than 100 billion MD5 guesses per second on one modern GPU.

Two more problems make it worse:

  • No salt by default. Hash “password123” with SHA-256 and you get the same string on every site in the world. Attackers keep huge precomputed lists of these, called rainbow tables, and simply look the hash up.
  • MD5 is broken as a hash. Researchers published practical MD5 collisions (two different inputs with the same hash) in 2004. It should not be used for anything security related.

The OWASP Password Storage Cheat Sheet says it plainly: fast algorithms such as SHA-256 are not suitable for password storage.

Salt, Pepper and Cost: The Three Defenses

Salt

A random value, different for every password, stored next to the hash. Two users with the same password get different hashes, and rainbow tables stop working. NIST asks for at least 32 bits; libraries use 16 bytes (128 bits).

Cost (work factor)

A setting that makes each hash slow on purpose: more rounds, more time or more memory. 20 to 300 milliseconds is nothing for one login, but it divides an attacker’s guessing speed by millions.

Pepper (optional)

A secret key added to every password, kept outside the database, for example in a secrets vault, a key management service or an HSM. If only the database leaks, the hashes are useless without it.

NIST’s current password rules, SP 800-63B revision 4 (final in July 2025), say the same thing in formal language: salt every password, use an approved password hashing scheme, and set the cost “as high as practical” for your servers.

The 6 Password Hashing Algorithms, One by One

Ordered from the best choice to the worst, following OWASP. Each one shows where it is used, how hard it is to crack and which attacks it resists. Crackability comes from our own speed test (see the timing table below), not from a percentage: real cracking success depends mostly on how weak the password is. Each one ends with a worked example: the same password, Sunny!Day42, run through that algorithm on our test PC. In the attack tags, ✓ means it resists that attack, “partly” means it slows it down, and ✗ means it does not help.

  • Brute force: trying passwords one after another, often from a list of leaked passwords.
  • GPU: using graphics cards to run thousands of guesses at the same time.
  • ASIC: chips built only for cracking one algorithm, much faster and cheaper per guess.
  • Rainbow table: looking a hash up in a huge precomputed list. A unique salt per password defeats it.

01 Argon2id: The Best Choice Today

  • 2015
  • Memory-hard
  • Usage: New web applications, APIs and password managers. The first choice in OWASP and RFC 9106.
  • Crackability: Very hard. About 48 guesses per second on one CPU core in our test, and every guess needs 19 MiB or more of memory.

Attacks it resists:

  • Brute force ✓
  • GPU ✓
  • ASIC ✓
  • Rainbow table ✓

Argon2 won the Password Hashing Competition in July 2015 and became RFC 9106 in 2021. Argon2id is the variant everyone recommends. Besides time, it needs a block of memory for every single guess, which is exactly what graphics cards and custom cracking chips are short of.

Settings: OWASP’s minimum is 19 MiB of memory, 2 iterations and 1 thread (m=19456, t=2, p=1). RFC 9106 suggests 64 MiB and 3 iterations for normal servers, which is what Python’s argon2-cffi uses by default. More memory is better if your server can afford it.

Argon2id example: the password Sunny!Day42 goes through Argon2id and comes out as a hash
Argon2id example with a real output: the output is one string that holds the settings, the salt and the hash.

02 scrypt: Good When Argon2id Is Missing

  • 2009
  • Memory-hard
  • Usage: Apps where Argon2id is not available. Also used as the proof of work in some cryptocurrencies, such as Litecoin.
  • Crackability: Very hard. About 3 guesses per second on one core at N=2^17, with 128 MiB of memory per guess.

Attacks it resists:

  • Brute force ✓
  • GPU ✓
  • ASIC ✓
  • Rainbow table ✓

Colin Percival created scrypt in 2009; it became RFC 7914 in 2016. It was the first popular memory-hard function and is also used by some cryptocurrencies. It is a good second choice, but its three settings are easier to get wrong than Argon2id’s.

Settings: OWASP’s minimum is N=2^17 (128 MiB), r=8, p=1.

scrypt example: the password Sunny!Day42 goes through scrypt and comes out as a hash
scrypt example with a real output: a 256-bit key that is stored together with its salt and settings.

03 bcrypt: Proven, but Keep It for Existing Systems

  • 1999
  • 72-byte limit
  • Usage: Existing and legacy systems. It is PHP’s PASSWORD_DEFAULT and what WordPress 6.8 uses.
  • Crackability: Hard. About 5 guesses per second on one core at work factor 12, but GPUs and custom chips do better against it than against Argon2id because it needs only 4 KB of memory.

Attacks it resists:

  • Brute force ✓
  • GPU (partly)
  • ASIC (partly)
  • Rainbow table ✓

bcrypt was presented at USENIX in 1999 and has held up for more than 25 years. It is slow on purpose but uses very little memory, so modern GPUs handle it better than they handle Argon2id. OWASP now lists it for legacy systems where Argon2id and scrypt are not available.

Watch out: bcrypt only reads the first 72 bytes of a password. Older libraries cut the rest silently; the current Python bcrypt package refuses with an error. Do not fix this by hashing the password with SHA-256 first unless you follow OWASP’s exact advice, because that can introduce new weaknesses.

Settings: a work factor of at least 10. PHP 8.4 now defaults to 12.

bcrypt example: the password Sunny!Day42 goes through bcrypt and comes out as a hash
bcrypt example with a real output: a 60-character string with the work factor and salt built in.

04 PBKDF2: For FIPS-140 Rules

  • 2000
  • Government and finance
  • Usage: Systems that must follow FIPS-140, such as government and banking. It is also Django’s default password hasher.
  • Crackability: Hard on a CPU, easier on a GPU. About 4 guesses per second on one core at 600,000 rounds, but it uses almost no memory, so a graphics card runs thousands of guesses in parallel.

Attacks it resists:

  • Brute force ✓
  • GPU ✗
  • ASIC ✗
  • Rainbow table ✓

PBKDF2 comes from the PKCS #5 standard, published as RFC 2898 in 2000 and now RFC 8018. It repeats a normal hash (HMAC) many thousands of times. It is the one to use when you must meet FIPS-140, which is common in government and banking. It uses almost no memory, so it needs a very high iteration count to stay safe.

Settings (OWASP): 600,000 iterations with HMAC-SHA-256, or 220,000 with HMAC-SHA-512. HMAC-SHA-1 needs 1,400,000 and is for old systems only.

PBKDF2 example: the password Sunny!Day42 goes through PBKDF2 and comes out as a hash
PBKDF2 example with a real output: a 256-bit key made by repeating HMAC-SHA-256 600,000 times.

05 SHA-256: Fine for Files, Wrong for Passwords

  • 2001
  • Too fast
  • Usage: File checksums, software downloads, TLS certificates, digital signatures and Bitcoin. Not passwords.
  • Crackability: Very easy. About 1.8 million guesses per second on one core in plain Python, and billions per second on a GPU.

Attacks it resists:

  • Brute force ✗
  • GPU ✗
  • ASIC ✗
  • Rainbow table ✗

SHA-256 is a secure hash and is used everywhere, from TLS certificates to software downloads. It is not broken. It is simply far too fast for passwords and has no salt or cost setting of its own. You will find it inside PBKDF2, which is the safe way to use it for passwords.

SHA-256 example: the password Sunny!Day42 goes through SHA-256 and comes out as a hash
SHA-256 example with a real output: the same 64-character digest every time, with no salt.

06 MD5: Broken, Never Use It

  • 1992
  • Broken
  • Usage: Old file checksums and non-security IDs. Never passwords or signatures.
  • Crackability: Very easy. About 1.6 million guesses per second on one core in plain Python, and over 100 billion per second on one modern GPU.

Attacks it resists:

  • Brute force ✗
  • GPU ✗
  • ASIC ✗
  • Rainbow table ✗

MD5 is fast, unsalted by default and has known collisions. If a system you look after still stores MD5 password hashes, treat it as an urgent fix. The section on upgrading old hashes below shows how to move away without forcing everyone to reset their password.

MD5 example: the password Sunny!Day42 goes through MD5 and comes out as a hash
MD5 example with a real output: the same 32-character digest every time, with no salt.

Password Hashing Algorithms Compared

Password hashing algorithms compared: usage, attacks resisted and crackability for Argon2id, scrypt, bcrypt, PBKDF2, SHA-256 and MD5
Top: the parts of a real Argon2id hash. Bottom: the six algorithms compared by usage, the attacks they resist and how hard they are to crack. Tap the picture to see it full size.
AlgorithmMemory-hardOWASP minimum settingUse it when
Argon2idYesm=19 MiB, t=2, p=1Building anything new
scryptYesN=2^17, r=8, p=1Argon2id is not available
bcryptNoWork factor 10 or moreThe system already uses it
PBKDF2No600,000 rounds (HMAC-SHA-256)FIPS-140 compliance is required
SHA-256NoNot for passwordsChecking files and messages
MD5NoNot for passwordsNever for security

How Slow Is Slow? Our Test Results

We timed one hash of the same password with each algorithm, using the settings above, on a normal office PC with Python 3.12:

Algorithm and settingsTime for one hashGuesses per second on one core
MD5under 0.001 msabout 1,600,000
SHA-256under 0.001 msabout 1,800,000
Argon2id, OWASP minimum (19 MiB)21 msabout 48
Argon2id, argon2-cffi default (64 MiB)38 msabout 26
bcrypt, work factor 12190 msabout 5
PBKDF2-SHA-256, 600,000 rounds238 msabout 4
scrypt, N=2^17324 msabout 3

A login that takes a fifth of a second is fine for a user. For an attacker, the same delay turns a guess list that MD5 would finish in a minute into one that takes weeks or months. Your numbers will differ with your CPU; the gap will not.

Try Password Hashing Yourself in Python

The argon2-cffi package does all the work: random salt, safe defaults and a single string to store. Install it:

Any OS · Python (pip)
python -m pip install argon2-cffi

Save this as hash_demo.py:

Python · hash_demo.py
from argon2 import PasswordHasher
from argon2.exceptions import VerifyMismatchError

ph = PasswordHasher()  # defaults: t=3, m=64 MiB, p=4 (RFC 9106 low-memory profile)

stored = ph.hash("correct horse battery staple")
print(stored)

try:
    ph.verify(stored, "correct horse battery staple")
    print("Password OK")
    if ph.check_needs_rehash(stored):
        stored = ph.hash("correct horse battery staple")  # save this new hash
except VerifyMismatchError:
    print("Wrong password")

Run it:

Any OS · Python
python hash_demo.py

You will see something like $argon2id$v=19$m=65536,t=3,p=4$... and then Password OK. Run it twice and the hash changes each time, because the salt is new. That is expected: verify reads the salt and settings from the stored string. check_needs_rehash tells you when a stored hash uses older, weaker settings, so you can upgrade it the next time that user logs in.

Password Hashing in PHP and WordPress

PHP has it built in. This ran as shown on our own PHP 8.4 server:

PHP · login check
$password = 'correct horse battery staple';
$hash = password_hash($password, PASSWORD_ARGON2ID);

if (password_verify($password, $hash)) {
    if (password_needs_rehash($hash, PASSWORD_ARGON2ID)) {
        $hash = password_hash($password, PASSWORD_ARGON2ID); // save the new hash
    }
}

PASSWORD_ARGON2ID needs PHP 7.3 or newer built with Argon2 support (most hosts have it). PASSWORD_DEFAULT is still bcrypt. See the password_hash manual.

WordPress moved from its old phpass hashes to bcrypt in version 6.8 (2025). It hashes the password with SHA-384 first so long passwords are not cut at 72 bytes, and older hashes are upgraded the next time each user logs in.

Upgrading Old MD5 or SHA Hashes

You cannot convert a hash into a different hash, because you do not have the passwords. Two safe ways out:

  1. Upgrade on login. When a user logs in successfully with the old hash, you briefly have the real password. Hash it with Argon2id, save that, and delete the old value. After a few months, force a password reset for accounts that never logged in.

  2. Wrap the old hashes now. Run Argon2id over every stored MD5 or SHA value today, so the whole table is protected at once, and mark those rows. At each login, check the password the same way (old hash first, then Argon2id), then replace it with a normal Argon2id hash.

Common Password Hashing Mistakes

  1. Encrypting passwords instead of hashing them. Whoever gets the key gets every password back.

  2. Writing your own scheme. SHA-256 run a few times with a homemade salt is still fast. Use a tested library.

  3. One salt for everybody. A shared salt lets attackers crack all accounts in one pass. Each password needs its own.

  4. Setting the cost once and forgetting it. Hardware gets faster every year. Review the settings and use the rehash check to raise them.

  5. Keeping the pepper in the same database. Then it protects nothing. Store it in a vault or HSM, or skip it.

  6. Logging passwords. Debug logs and error reports that contain the raw password undo all of the above.

Key takeaways

  • Argon2id first, then scrypt; bcrypt for existing systems; PBKDF2 when FIPS-140 applies.
  • MD5 and SHA-256 are far too fast for passwords, even with a salt.
  • Every password needs its own random salt and a deliberately slow cost setting.
  • Use a library (argon2-cffi, PHP’s password_hash) instead of your own code.
  • Upgrade old hashes on login, and raise the cost as hardware improves.

Password Hashing FAQ

Which password hashing algorithm is best in 2026?

Argon2id, with at least 19 MiB of memory and 2 iterations. Both OWASP and RFC 9106 recommend it for new systems.

Is bcrypt still safe?

Yes, with a work factor of 10 or more (12 is a good default today). OWASP now lists it for legacy systems because Argon2id resists GPU cracking better, and bcrypt only reads the first 72 bytes of a password.

Is SHA-256 with a salt good enough for passwords?

No. The salt stops rainbow tables, but each guess still takes well under a microsecond, so attackers can try billions per second on a GPU. Use SHA-256 only inside PBKDF2 with a high iteration count, or use Argon2id.

What is the difference between hashing and encryption?

Encryption can be reversed with a key; hashing cannot. Passwords should be hashed, so that even the site owner cannot read them.

Do I need to store the salt separately?

No. Modern formats put the algorithm, settings, salt and hash into one string, such as $argon2id$v=19$m=19456,t=2,p=1$salt$hash. The salt is not a secret.

Official references: the OWASP Password Storage Cheat Sheet, NIST SP 800-63B-4, RFC 9106 (Argon2) and the WordPress post WordPress 6.8 will use bcrypt.

Related Guides on infotechtu.com

Share this guide

Save

Get new guides by email

One short email when a new guide is out. Unsubscribe at any time.

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top