Mix password hashing that stands up to rainbow tables and brute force: 18 levels of salts, work factors, timing attacks and threat modeling.
A good server does not store passwords, only their hash: a fingerprint you can compute from the password but cannot reverse. At login the typed password is hashed again and matched. The weakness: the same password always hashes the same, so a thief can compute the hashes of thousands of common passwords before stealing anything, then just look up. That is a rainbow table. A salt is a random string mixed into the password before hashing and stored next to the hash.
A salt that is the same for everyone is usually written in code. A thief who targets this book reads it, and then one computation per guess is enough to test all the rows at once. Two people with the same password also get the same row. A random per-user salt (from crypto.getRandomValues) makes every row different and forces the thief to compute again for each person.
A == comparison stops at the first byte that differs. A guessed hash that matches two bytes in is answered a little slower than one that differs at once, and an attacker who times the answer learns the stored hash a little at a time. A constant-time comparison checks all the bytes every time, match or not.
A thief who holds the book guesses without limit on their own device. The only brake is the cost of each guess. MD5 and SHA-256 are made as fast as possible. A password function is slow on purpose and can be tuned: Argon2id uses memory (OWASP: 19 MiB, 2 passes), bcrypt doubles the work each time its cost goes up (OWASP: at least 10), PBKDF2 repeats HMAC many times (OWASP: 600,000 rounds for SHA-256). bcrypt and Argon2id make their own random salt.
Each login computes the hash once, at the same cost as one of the thief’s guesses. Work that is too high makes the server itself choke when many people log in. Times in this game are measured on a laptop like the cash laptop (PHP 8.4 and OpenSSL): bcrypt cost 10 about 80 ms and each extra cost doubles it, PBKDF2 600,000 rounds about 75 ms, Argon2id 19 MiB about 38 ms.
bcrypt was made in 1999 and reads only the first 72 bytes of a password. A longer password is quietly cut, so anyone who knows its first 72 bytes can get in, whatever the rest is. Laravel on the server next door uses bcrypt and does not cut anything itself. Argon2id and PBKDF2 read the whole password.
And more, 18 levels in all.