Hashing passwords
Fill-gap25 min
Hashing passwords
Never store a password. Store a hash — a one-way transformation:
const hash = await argon2.hash(password);
// later: verify, never decrypt
await argon2.verify(hash, attempt);Hashing is not encryption: there is no key, no way back. The database stores $argon2id$…, and login works by hashing the attempt the same way and comparing outputs.
If the database leaks, attackers do not get passwords — they get expensive guesses. That is the whole design. This app's auth/password.service.ts is the real implementation used by your login.
Exercise
Read src/auth/password.service.ts. Write the two functions it implements (hash, verify) in pseudocode, and explain why there is no decrypt.