What is a hash — and why your password can't be turned back

Here's a simple honesty test for any service. You click "forgot password" — and your inbox gets your old password. Not a reset link, the actual password, in plain text.
That means the service stores it in a readable form. Steal the database, steal the password. A decent service literally can't do that — it doesn't know your password. And yet it lets you in correctly every single time.
The trick is called a hash.
What a hash is, in plain words
A hash is a one-way meat grinder for data.
You feed it anything: a word, a password, a two-gigabyte file. Out comes a fixed-length string — say 64 characters. Always 64, whether you fed it one letter or an entire movie.
Two iron rules:
- Same input → always the same output. The hash of
hellotoday and in ten years matches character for character. - No way back. You can't reassemble a cow from mince.
And the detail that makes it all work: change one character on the input and the hash changes completely, not "a bit". hello and hollo give two utterly unalike strings. No resemblance survives, nothing to grab onto.
How a service lets you in without knowing your password
So here's what actually happens when you sign up.
- You pick a password. The server runs it through the grinder and stores only the hash. The password itself gets thrown away.
- You come back and type the password again. The server runs the input through the same grinder.
- It compares the two hashes. A match means you typed the same thing. You're in.
The server compares fingerprints, not passwords. Which is why it can't mail you your password — it doesn't have it. The most it can do is send a link and store a new hash.
Hence a red flag worth memorising: if a service emails you your password in plain text, it stores passwords readably. Don't keep anything important there.
Salt: why identical passwords get different hashes
There's a hole. A hash is deterministic — so 123456 turns into the same string for everyone. An attacker pre-computes hashes for a million popular passwords, gets a ready-made table, and looks for matches in a stolen database. That's a rainbow table.
The cure is salt. Before hashing, a random string is mixed into the password — a different one per user:
hash("hello" + "x7Kq2")
The salt sits next to the hash and isn't a secret. But now two people with the password hello get different hashes, and the pre-computed table is useless: it has to be rebuilt for every single salt.
Good news: decent libraries generate and mix the salt for you. You don't do it by hand — you just don't try to "improve" on how they work.
Why SHA-256 is a bad choice specifically for passwords
This is where people get burned most often. SHA-256 is a strong hash; it isn't "crackable". But for passwords it's bad for an unexpected reason: it's too fast.
An attacker holding a stolen database doesn't decrypt anything — they guess. Take a dictionary word, mix in your salt, compute the hash, compare. A modern GPU does this billions of times per second. A simple password falls in minutes.
That's why passwords use hashes that are deliberately slow and memory-hungry: Argon2, bcrypt, scrypt. OWASP's current recommendation is Argon2id (at minimum 19 MiB of memory, 2 iterations, 1 thread). One check takes tens of milliseconds — invisible to you at login, but it makes brute force millions of times more expensive.
The bcrypt trap: 72 bytes, and some letters weigh two
One last detail that trips up even people who did everything else right.
bcrypt only reads the first 72 bytes of a password. Everything past that it silently discards — no error, no warning. A hundred-character password gets verified on its first 72, and you'll never know.
Now the important part: the limit is in bytes, not characters. A Latin letter is 1 byte. A Cyrillic letter in UTF-8 is 2 bytes. So a long passphrase in Russian hits the ceiling at roughly 36 characters — twice as early as an English one. Same story as with the tokenizer: non-Latin text costs more because it weighs more.
What to do about it? Don't hand-roll hashing. Take Argon2id or ready-made authentication — it's already solved there. And keep secret keys in environment variables, not in your code.
FAQ
Is a hash the same thing as encryption?
No, and the difference is fundamental. Encryption is two-way: with the key you decrypt it back. A hash has no reverse operation at all. That's why passwords are hashed, not encrypted — nobody needs to read them back.
Can two different passwords produce the same hash?
In theory yes — it's called a collision, since there are infinitely many inputs and a finite number of outputs. In practice, with modern hashes the odds are so small that neither defence nor attack plans around it.
How is a hash different from base64?
base64 isn't protection, it's a way of writing data: it unwraps in one line, no key needed. Simple rule — if the data can be recovered, it's encoding, not a hash.
The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.





