Storing passwords safely (hashing with salt)
In short: An application must never store passwords in plain text. It stores only a hash with salt from which the password cannot be recomputed.
In more detail: On sign-in the entered password is hashed with the same method and compared with the stored value. The salt is a random addition per user. It prevents identical passwords from producing identical hashes and makes precomputed tables (rainbow tables) useless.
In Depth
- Right methods: Argon2id, scrypt, bcrypt or PBKDF2 with a high iteration count. They are deliberately slow and memory-hungry.
- Wrong: MD5, SHA-1 or plain SHA-256 without salt. They are cracked too quickly.
- Pepper: an additional secret that is not in the database.
- Length counts: Allow long passwords, require only a minimum length, no forced special characters.
- Checking: comparison with lists of known leaks.
See also: Hashing, Password manager