Tools and labs
Password Hashing Explained: Hashing vs Encryption, Salts and bcrypt
When a company says passwords were stored "securely", what does that actually mean? The answer is hashing, done properly. Here is how it works, why some methods fail, and what good practice looks like.
Hashing vs encryption
- Encryption is two way. You lock data with a key and unlock it with a key. Good for messages and files you need to read later.
- Hashing is one way. You put data in and get a fixed length output, like a fingerprint. You cannot turn the fingerprint back into the data.
For passwords, a website does not need to know your password. It only needs to check that what you type matches. So it stores the hash, and at login it hashes what you typed and compares. If the database leaks, attackers get hashes, not passwords, at least in theory.
Properties of a good hash function
- The same input always gives the same output.
- A tiny change in input gives a completely different output.
- You cannot practically reverse it.
- It is very hard to find two inputs with the same output.
Try it yourself with the hash tool on our home page tools section, or on Linux:
echo -n "hello" | sha256sum
echo -n "hellO" | sha256sum
The two outputs look nothing alike, even though only one letter changed.
Why fast hashes are bad for passwords
SHA-256 is excellent for checking file integrity, see our SHA-256 download guide. But it was designed to be fast. If attackers steal a database of SHA-256 password hashes, they can try enormous numbers of guesses per second on graphics cards, hashing common passwords and comparing. Weak passwords fall quickly.
MD5 and SHA-1 are worse: they are fast and also have known cryptographic weaknesses. They should not be used for passwords.
Salts: making every hash unique
If two users have the password "Mumbai@123", a plain hash would be identical for both, and attackers could use precomputed tables of hashes for common passwords. A salt is a random value generated for each password and stored alongside the hash. The system hashes salt plus password. Now identical passwords produce different hashes, and precomputed tables become useless.
Salts are not secret. Their job is uniqueness, not hiding.
Slow algorithms: Argon2id, scrypt, bcrypt
Password hashing algorithms are designed to be deliberately slow and costly, with a work factor you can tune. One login check taking a fraction of a second is fine for a user, but it makes billions of guesses very expensive for an attacker.
The OWASP Password Storage Cheat Sheet recommends Argon2id as the first choice, with scrypt and bcrypt as alternatives in suitable cases, and PBKDF2 where compliance requires it, each with appropriate parameters. Some systems also add a pepper, a secret value stored separately from the database, as an extra layer.
What this means for you as a user
You cannot see how a website stores your password. That is exactly why:
- Use a unique password for every site, so one weakly protected site cannot expose others.
- Make passwords long, since long passphrases resist guessing even when hashes leak.
- Turn on 2FA or passkeys, which protect you even if the password is cracked. See our passkeys explainer.
Practise safely
In your lab, write a small Python script that hashes passwords with a salt using a library such as bcrypt or argon2-cffi, and verifies them. Notice how changing the work factor changes the time taken. Never test password cracking against real accounts or leaked databases of real people. Use only your own test hashes or CTF challenges built for this purpose.
Frequently asked questions
Is encryption ever used for passwords? Websites should not store passwords with reversible encryption, because anyone with the key could recover them all. Password managers are different: they encrypt your vault so you can read your own passwords.
What is a rainbow table? A large precomputed table of hashes for common passwords, used to reverse unsalted hashes quickly. Unique salts make rainbow tables ineffective.
Why do websites limit login attempts? Rate limiting slows down online guessing. Hashing protects the stored passwords if the database leaks. Both work together.
Educational content, not legal advice. Check official sources before you rely on it. If you have lost money, call 1930 now. Terms