Password Hashing and Secure Storage
Explain how salted, slow password hashing lets a server verify a password it never stores, and spot signs of plaintext password storage.
Where your password goes after you press Log in
Every month Mrs. Lata Gokhale opens the Tulsi Health app, types her phone number and password, and reorders her blood-pressure tablets. The app's server, the computer in the cloud that answers every phone running the app, has to decide in a fraction of a second whether that password is right. To do that it must keep something about her password in its database, the organised store of records where customer accounts live. Rohan Iyer, who builds the app, has to choose what exactly to keep. The simplest choice is the password itself, and it is also the most dangerous one.
Why storing passwords as they are is a disaster
Keeping passwords exactly as people typed them is called plaintext password storage, plaintext meaning readable as it is. It works perfectly until the day someone else sees the table. That can happen in many ways: an attacker breaks into the database, a backup copy is left on a shared drive, a developer's laptop with a test copy is stolen, or a curious insider simply looks.
The same stolen table, stored two ways. On the left the thief has every password. On the right the thief has only fingerprints, and even the two identical passwords look different.
The damage does not stop at Tulsi Health. Most people reuse passwords, so a stolen list of phone numbers and passwords gets tried automatically on email, shopping and banking sites. This is called credential stuffing: stuffing stolen login pairs into other websites to see which ones open. A plaintext breach at one pharmacy app can become a hijacked email account for Mrs. Gokhale, from which an attacker can reset everything else. So the rule is simple: a service should never be able to read your password, not even its own staff.
Store a fingerprint, not the password
The answer is password hashing. When Mrs. Gokhale first sets her password, the server runs it through a hash function, a one-way calculation that turns any text into a fixed-length fingerprint called a hash value. The server stores only that fingerprint and throws the password away. Like a mixer-grinder that turns coconut into chutney, the calculation cannot be run backwards, so the stored value does not reveal the password.
Logging in then becomes a comparison, a step called password verification. The server hashes whatever she types now, using exactly the same method, and compares the result with the stored fingerprint. Same password, same fingerprint, so she is let in. A wrong password produces a completely different fingerprint, so she is not.
The password is used for a moment and then forgotten. Only the salt and the fingerprint are ever saved.
Why a plain hash is not enough
Hashing alone still leaves two gaps, and both come from the fact that people pick predictable passwords. First, identical passwords give identical fingerprints. If Farida and Riya both chose Tulsi@123, their stored hashes are the same, so cracking one cracks both, and an attacker can see straight away which passwords are popular.
Second, attackers do not need to reverse a hash; they can guess forwards. They take a list of the most common passwords, hash each one, and look for matches in the stolen table. This is a dictionary attack. Criminals even keep huge ready-made lists of common passwords already paired with their fingerprints, so a match is just a lookup. The lab below shows why a plain, unsalted hash of a common password protects almost nothing: you are given one stolen fingerprint and a short list of popular passwords, and you find which one it came from.
Salt: a pinch of masala unique to each household
The fix for both gaps is salting. When an account is created, the server generates a salt, a random string that is different for every account, and hashes the salt joined to the password instead of the password alone. Think of every household's chai: the same tea leaves, but each home adds its own pinch of masala, so no two kitchens' chai tastes the same. Farida's salt is 9f2c and Riya's is e871, so their identical passwords now produce completely different fingerprints.
The salt is stored right next to the hash and does not need to be secret; its job is to make every account different, not to be a second password. That one change breaks the attacker's shortcuts. Ready-made lookup lists become useless, because nobody built a list for the salt 9f2c, and a dictionary attack must now be run separately for every single account. Try it below: keep the password the same, change the salt, and watch the stored value change completely.
Slow on purpose
There is one more twist. General-purpose hash functions such as SHA-256 are built to be fast, which is good for checking a large file but bad for passwords. A single gaming graphics card can compute billions of SHA-256 values a second, so even a salted list of weak passwords falls quickly. Proper password storage therefore uses a password hashing function that is deliberately slow and, in some cases, also needs a lot of memory for each guess. The common ones are bcrypt, scrypt and Argon2. They have a cost setting that can be raised as computers get faster: a tenth of a second is nothing when Mrs. Gokhale logs in once, but it is crippling for someone trying millions of guesses.
Each step to the right takes away one of the attacker's shortcuts. Only the last one is acceptable for a real app.
Try it: an attacker steals all 2.4 lakh customer records and tries a list of 1 crore common passwords. How long does it take with a fast unsalted hash, and with a salted slow one?
Assume one graphics card manages 10 billion fast SHA-256 guesses a second, but only 1,000 guesses a second against a slow password hash. With a fast, unsalted hash, the attacker hashes the 1 crore (10 million) passwords once and looks up every stolen fingerprint: 10,000,000 ÷ 10,000,000,000 = 0.001 seconds for all accounts together. With a salted slow hash, each account needs its own run: 10,000,000 ÷ 1,000 = 10,000 seconds, about 2.8 hours, for one customer. For all 2,40,000 customers that is 2,40,000 × 10,000 = 2.4 billion seconds, roughly 76 years. Weak passwords still fall eventually, one by one, but the attacker can no longer harvest the whole table at once.
Secure storage beyond the hash
The hash is the centre of good password storage, but a few habits around it matter just as much. Passwords should travel from phone to server only over an encrypted connection, so nobody on the café Wi-Fi can read them. They must never be written into logs, the running records servers keep of what happened, where they would sit in plaintext after all. The database itself should be reachable only by the app and a small number of named people, and limits on repeated wrong guesses plus a second login step protect accounts whose password does leak.
There is also a clue you can use as a customer. If a website's "Forgot password" button ever emails you your old password, that service is storing passwords in a form it can read, and you should not reuse that password anywhere. A properly built service cannot tell you your password, because it does not know it; it can only send a link to set a new one.