Security5 min read10 interview questions
How passwords should be stored
Why a good site never keeps your actual password.
In one sentenceSites should store a scrambled fingerprint of your password that cannot be turned back into the password.
Think of it like thisIt is like keeping only a wax impression of a key: you can check if a key fits, but you cannot cut a new key from the impression.
The big picture
Tap any step to see where to use it, how to use it and an example result.
Hashing, not encryption
Encryption can be reversed with a key. A hash cannot be reversed. When you sign in, the site hashes what you typed and checks whether it matches the stored hash.
Why salt
A salt is a random value added to each password before hashing. Two people with the same password get different hashes, and attackers cannot use one precomputed list against everyone.
Why slow is good
General hashes are fast, which helps attackers try billions of guesses. Password hashes such as Argon2, bcrypt and PBKDF2 are deliberately slow and costly, so each guess takes time.
Common mistakes
- Storing passwords in plain text or with a fast hash such as plain SHA-256.
- Writing your own scheme instead of using a trusted library.
- Limiting passwords to short lengths or banning symbols.
Quick recap
- Store a hash, never the password
- Add a random salt for each user
- Use a slow password hash such as Argon2 or bcrypt
- Use a library, do not invent your own
Try it yourself
Use a bcrypt or Argon2 library in your language to hash the same password twice and see that the two results differ, yet both verify correctly.
Top 10 interview questions
Ordered from basic to advanced. Try answering out loud first, then open the answer.
Why should passwords never be stored in plain text?Basic
If the database leaks, everyone's passwords are exposed, and since people reuse passwords, their other accounts are at risk too.
What is hashing?Basic
A one-way function that turns input into a fixed-length fingerprint. You cannot turn the hash back into the original, but the same input always gives the same hash.
What is the difference between hashing and encryption?Basic
Encryption can be reversed with a key. Hashing cannot be reversed. Passwords should be hashed because the server never needs to read the original.
How does login work with hashed passwords?Basic
At signup the hash is stored. At login the server hashes the password entered and compares it with the stored hash, so the real password is never saved.
What is a salt and why is it used?Intermediate
A random value added to each password before hashing and stored with the hash. It makes identical passwords produce different hashes and defeats precomputed lookup tables.
Why not use plain SHA-256 or MD5 for passwords?Intermediate
They are designed to be fast, so attackers can test billions of guesses per second. Password hashes should be deliberately slow and memory-hungry.
Which algorithms are recommended for passwords?Intermediate
Argon2id is the usual first choice, with scrypt, bcrypt or PBKDF2 as accepted alternatives. Use a well-tested library and its recommended settings.
What is a pepper?Intermediate
A secret value added to passwords before hashing and kept outside the database, for example in a secrets manager. It adds protection if only the database is stolen.
How do you upgrade password hashing without asking users to reset?Advanced
Verify with the old algorithm at login, then rehash the password with the new one and save it. You can also wrap old hashes in the new algorithm straight away.
What other protections belong next to hashing?Advanced
Rate limiting and lockouts for guessing, multi-factor authentication, checking against known breached passwords, secure reset flows and not logging passwords.
Guides are simplified on purpose. Tool names and details change, so check the official documentation before relying on a detail.