Fast code is usually good. For passwords, it's a gift to attackers. Here's why slow hashing, salts and Argon2 keep a leaked database from hurting you.
Most of computer science is about making things faster. Password hashing is the exception: it is made slower on purpose.
Here is the question for this article. If an attacker steals the database, why does a slow function protect you when a fast one does not?
A hash works like a one-way blender. You put a password in, a scrambled string comes out, and you can't turn it back. A site stores the scrambled string, not your password, so it never has to keep the real thing.
When you log in, the site scrambles what you typed and checks whether the result matches. The same input always gives the same output. That last fact is where the trouble starts.
So what happens when someone steals that database?
Say a database leaks. The attacker doesn't get passwords. They get the scrambled strings.
So they play a guessing game. They take a guess, scramble it, and compare it to the leaked string. If it matches, they found the password. A hash can't be reversed, but it can be guessed at. That is the whole attack.
Click Next to follow one guess. The attacker repeats steps 2 to 4 again and again.
The attacker holds a leaked scrambled string
Each guess costs one hash. So the cheaper one hash is, the more guesses the attacker gets.
So how fast are normal hashes?
Hashes like SHA-256 were built to be quick, which is great for checking files. For passwords, that speed helps attackers. OWASP (a group that writes security guides) says fast hashes "allow attackers to perform large numbers of guesses quickly."
The Provos and Mazières bcrypt paper has a neat history lesson. In 1976, Unix crypt could hash fewer than 4 passwords per second. About 20 years later, a fast workstation could do over 200,000 per second. That's roughly 50,000 times faster.
Computers keep getting faster, so a password scheme that never changes keeps getting weaker. The paper's main point is that the cost of a secure password scheme has to grow as hardware improves.
What about salt? Does it fix this?
Two users with the same password get the same scrambled string. That's bad, because cracking one cracks both. An attacker could even prepare a giant lookup table of common passwords ahead of time.
A salt fixes this. It's a random string, unique per user, mixed into the password before hashing. OWASP describes it as "a unique, randomly generated string that is added to each password."
A random extra input, different for every user. It stops lookup tables and makes identical passwords look different. It does not slow down guessing.
The last line matters. The bcrypt paper says it too: a salt doesn't stop brute-force guessing. It only removes the shortcuts. A salt is not a substitute for slowness.
So we also need something that makes every single guess expensive.
If one hash takes a tiny moment, a login still feels instant to you. But an attacker needs millions of guesses, so that tiny moment adds up to a huge cost.
OWASP's advice is that the hash should take less than about one second. You wait once. The attacker waits millions of times.
So which slow hash should you pick?
| Name | The idea | What OWASP and the sources say |
|---|---|---|
| bcrypt | Has a cost setting you raise over time | Work factor at least 10; input limit around 72 bytes in most implementations |
| scrypt | Slow, and also needs lots of memory | N=2^17 (128 MiB), r=8, p=1 as a minimum |
| Argon2id | Slow and memory-hungry, the modern pick | Minimum 19 MiB memory, 2 iterations, 1 parallelism |
Why memory? Special hardware can run thousands of cheap guesses at once, but memory is harder to fit into it. Argon2 is built to be "memory-hard", so each guess needs a big chunk of RAM. RFC 9106 says Argon2id MUST be supported by any implementation, and it's a blend of the two other variants.
All of these have a setting that decides how slow they are. Bcrypt calls it the work factor. Argon2 has memory, iterations and parallelism. More means slower.
The bcrypt paper says it plainly: the cost should rise as hardware gets better, and users will only tolerate so much delay. So pick the highest setting your server can afford, and check it again every year or so.
Never invent your own scheme. Use a well-known library, let it make the salt, and choose Argon2id if you can. Bcrypt is fine for older systems.
And remember what a leak really exposes: weak and common passwords go first, strong ones can survive. The hash buys you time. It is not magic. That's why a long, unique password still matters.