Passwords handling, despite its apparently triviality, is anything but. It usually comes up in two distinct use-cases:
For the former, the resources budget is pretty high: having your full-disk encryption take a couple of seconds to unlock itself is not only acceptable, but expected and kind of reassuring. For the latter, things are much more constrained, and for the rest of this post, we'll focus on it.
What we're trying to do here, is to make it as hard as possible for an attacker in possession of the database of our website to bruteforce the hashes to obtain the clear-text passwords of our users. As people tend to reuse passwords or variations across services, password leaks are a valuable resource for miscreants. And even if everyone was using unique passwords, storing them hashed increases the time it takes for an attacker to compromise accounts, increasing the odds that the breach will be discovered and passwords forcibly changed before being misused.
Let's have a look at what kind of levers we have at our disposition to make the process of cracking the hashes expensive for an attacker:
name | creation/release date | computationally hard | memory-hard | cache-hard | CPU-hard |
---|---|---|---|---|---|
MD5 | 1992 | no | no | no | no |
bcrypt | 1999 | yes | no | barely | no |
PBKDF2 | 2000 | yes | no | no | no |
scrypt | 2009 | yes | yes | no | no |
Argon2 | 2015 | yes | can be | Argond2ds | yes |
yescrypt | 2018 | yes | yes | yes | yes |
For a small web application, we:
So our main lever in our case is cache-hardness, leaving us with 3 candidates:
Now, bcrypt has some footguns, but if you're using a proper language or a well-designed library, those will handle them for you. Of course, if you're building a serious™ project, please do reach out to your friendly neighborhood security person, as again, password handling is a hard problem.
If you'd like to learn more on the topic, I'd recommend Solar Designer's Energy-efficient bcrypt cracking and yescrypt: large-scale password hashing, as well as Niels Provos' Bcrypt at 25: A Retrospective on Password Security, the Password Hashing Competition - Survey and Benchmark, Steve Thomas' bscrypt - A Cache Hard Password Hash talk, Soatok's blog posts on the topic, and more generally, the hashcat, HashMob and John the Ripper password cracking communities.