atmathExploreไทย

Everyday math · Phones & the internet

Why can’t a website tell you your old password?

Short answer: a website that stores passwords properly doesn’t keep your password at all. It keeps a “hash”, the output of a one-way function: going from password to hash is instant, but going from the hash back to the password is not possible. So the site has no old password to send back. All it can do is send you a link to set a new one.

A hash is a one-way function

Think of a function in math class: put in x, get out f(x). One widely used hash is SHA-256 (standard FIPS 180-4 from the U.S. institute NIST). Feed it a message of any length and you always get 256 bits out, which is 64 characters in hexadecimal.

Example: “atmath” and “atmatH” differ only in the last letter

SHA-256(“atmath”)a5e19fc5ead3b732433def686284bf131bdf64b58c3dadce35c3e4f019b00ff0

SHA-256(“atmatH”)88e8bcfc878e267e07c09d307853f9da865e1a14f5ffd204ef5c9cb1cf1f07db

129 of 256 bits differ · of the 64 hex characters, only 2 match (orange = different)

We repeated this on a computer 10,000 times (a random 8-character message, then 1 character changed): on average the hash changed 128.1 bits (fewest 98, most 156), almost exactly half of 256 bits, which is what a good hash function should do

How can a website check your password without storing it?

  1. When you sign up: the site picks a short random string just for you, called a salt, and stores only the salt and hash(salt + password). The real password is thrown away
  2. When you log in: what you type + the same salt are hashed again · matching hash = correct password
  3. When you forget it: the site has no old password to look at, so it sends a reset link · guidance from OWASP (a web security community) also says never send passwords by email

Flip it around: if you click “forgot password” and the site sends your old password back, it is storing passwords in a reversible form. Don’t reuse that password anywhere else.

Try it

⚠️ Don’t type a real password. Made-up words show the idea just as well (everything runs on your device; nothing you type is sent anywhere)

1 · Change 1 character: how much does the hash change?

2 · What does salt do?

2 people happen to use the same password · turn salt off and on and look at the hashes the site stores

Simple demo: hash = SHA-256(salt + password) · the salt is 32 bits

3 · If an attacker gets the hash, how long does guessing take?

Choose which kinds of characters the password may use, and its length · assume the password is random characters

Why it can’t be reversed

  1. Information is lost on the way (just count): there are endlessly many possible messages, but a 256-bit hash has only 2256 ≈ 1.2 × 10⁷⁷ possible values ⇒ many messages must share the same hash (the pigeonhole principle), so a hash doesn’t carry enough information to give the real password back
  2. No shortcut: SHA-256 mixes the bits with wrap-around addition (remainder after dividing by 232), shifts and rotations, repeated for 64 rounds · FIPS 180-4 calls it “secure” because finding a message that gives a chosen hash is computationally infeasible · what’s left is guessing one password at a time and comparing hashes

The attacker’s only way: guessing · longer takes longer

For a password L characters long, with n choices per character, there are nL possible passwords (the multiplication principle) · the table shows the time to try every one (on average the right one turns up in about half this time)

Wide table ⇒ swipe left and right to see it all

PasswordnLPossibilitiesFast hashSlow hash
4-digit PIN10410,000under 1 second1.0 seconds
8 lowercase268208,827,064,57621 seconds242 days
8 lower+upper+digits628218,340,105,584,8966.1 hours692 years
8, all 4 kinds9486.1 × 10¹⁵7.1 days19,329 years
12 lowercase26129.5 × 10¹⁶110 days302,603 years
15 lowercase26151.7 × 10²¹5,319 years5.3 × 10⁹ years

The guessing speeds are assumed numbers for comparison: fast hash 10 billion guesses per second · slow hash 10,000 guesses per second (1,000,000 times slower) · a year = 365 days

What salt is for

A salt is a random string unique to each person, attached to the password before hashing · OWASP explains that different salts make identical passwords produce different hashes, and stop attackers from using precomputed hash tables (rainbow tables) · NIST requires salts of at least 32 bits

Example: 2 people with the password “123456”

No salt (same for the 2 people)8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92

salt 9f2c4a1e43f396b73b8ec016aa9abacfc35c0f22667f24c4265d841ae41293ad85c4073b

salt 03b7d58ced0b2093066df075b9c918faa42173423f1726c8d470a9cd17dce48616b01a93

Why real websites don’t use plain SHA-256

Because it is too fast · OWASP says fast hashes like SHA-256 are unsuitable for storing passwords, since attackers can make huge numbers of guesses ⇒ sites should use functions designed to be slow on purpose, such as Argon2id (the first recommendation), scrypt, bcrypt or PBKDF2 · this page uses SHA-256 only to show the idea

Watch the video

Short video: Why can't a website tell you your old password when you press “forgot password”? (Thai audio)
Watch on YouTube · Watch on TikTok
Long video: Encrypt · Check · Repair: The Math That Protects Your Data Every Day (Thai / English audio)
Watch on YouTube

The video loads from YouTube (youtube-nocookie.com) only after you press play. · YouTube channel: atmath (@atmathapp)

The math behind it

Good to know

Next (cryptography series, part 2): a padlock anyone can lock but only one person can open, the prime-number math that lets us send secret messages

References

Accessed 19 Nov 2026 · the numbers and hashes on this page were computed with our own script (SHA-256 checked against the standard’s “abc” test value)

← More from Explore