Guides and sections
Cyber Guide
How websites store your password
Level: Going further
A well-built website does not keep your real password. It keeps a scrambled, one-way version called a hash, mixed with a random value called a salt. You cannot see how a site does this, so long, unique passwords are your protection.
The short version
This page is for the curious. You do not need it to stay safe, and the Passwords and two-step login guide covers what to do. This page explains what happens on the website's side.
When you create an account, the website should not save your password as you typed it. It saves a scrambled version instead. When you log in later, the site scrambles what you type in the same way and checks whether the results match.
Why not keep the real password?
OWASP, a group that publishes security guidance for people who build websites, says passwords should never be stored in plain text. Plain text means the readable password itself. A site's list of accounts can be stolen. If it holds real passwords, the thief can log in as everyone straight away.
What a hash is
A hash is the scrambled version. It is made by a one-way recipe. Put your password in and you always get the same hash out, but you cannot run the recipe backwards to get the password. OWASP describes hashing as a one-way function and says that even if an attacker obtains a hashed password, they cannot use it to log in as you.
What a salt is
If two people choose the same password, a simple hash would look the same for both. Attackers can also build huge lists of common passwords and their hashes in advance. These are called lookup tables or rainbow tables.
A salt fixes both problems. OWASP defines a salt as a unique, randomly generated string that is added to each password as part of the hashing process. The website makes the salt, not you. NIST, the United States standards body, says the salt and the resulting hash are both stored for each password. Because every account has its own salt:
- Two people with the same password end up with different stored hashes.
- Lists made in advance no longer work, and an attacker has to work on the accounts one at a time.
Without a salt
Ana
Ben
With a salt added by the website
Ana
Ben
You never add a salt yourself. If you have heard of people adding a word to the end of a password and calling it salt, that is a different idea. See "The base phrase trick" in Passwords and two-step login.
Slow on purpose
Not every recipe is suitable. OWASP and NIST both say a website should use a hashing method designed to be slow, so that each guess costs an attacker time. OWASP names Argon2id, scrypt, bcrypt and PBKDF2 as suitable. It says fast methods such as SHA-256 are not suitable for passwords, because they let an attacker make huge numbers of guesses quickly.
What this means for you
- A leaked list of good hashes is still a problem for weak passwords. OWASP explains that an attacker can hash common passwords and passwords from other leaks and compare the results. If your password is on one of those lists, it can be found. A long, unusual passphrase is far less likely to be.
- You cannot see how a site stores your password. OWASP says that strong passwords stored with modern hashing should be effectively impossible to crack, but it also says the cost of cracking drops when best practice is not followed. Some sites follow it better than others.
- So never reuse a password. A different password on every site means one site's mistakes cannot open your other accounts. Two-step login adds a second barrier.