You should use hashing instead of encryption for passwords
On this page
A developer stares at a database. He sees rows of random characters where passwords belong; he tells a coworker they’re encrypted. The coworker nods. This happens in offices every day. For years, people used one word for any process that turned plain text into gibberish, and encryption felt like the right term if the goal was to hide a secret.
A fundamental difference#
Encryption works both ways. You use a math key to lock your data and another key, or sometimes the same one, to open it back up. It turns plain text into cipher text. To anyone without that key, it’s just gibberish. The whole point is that you can get the original info back perfectly; this makes sense for sending a private message to a friend who actually needs to read your words.
Hashing isn’t like that. A hash function takes data and makes a unique digital fingerprint called a hash; it’s a one way street by design. There’s no key to reverse a hash because the original data isn’t actually hidden in the result. The system just stores the fingerprint. When you log in, the system hashes your password and compares it to that stored print. If they match, you’re in. Why would the system need to know the plain text password?
The problem with encrypting passwords is the key. A company has to put that decryption key somewhere. If an attacker steals the database and finds the key, every account is gone instantly. The thief doesn’t have to guess individual passwords when a master key lets them unlock everything while they enjoy a quiet cup of tea.
The slow path#
Early hashing was fast. That speed turned into a problem, and attackers started using heavy hardware to guess millions of common passwords every second, hashing those guesses and checking them against stolen databases. If the hashes matched, they had the password.
Security standards had to change. Groups like the National Institute of Standards and Technology set guidelines to make hashing intentionally slow. A slow hash function makes a computer run thousands of internal loops before it spits out a result, and a single user logging in won’t notice the lag, but for an attacker trying millions of combinations, it’s a disaster. It turns a job that takes hours into one that takes centuries.
Then there is salt. Salt is just a random string of characters added to a password before hashing, and this means two people using “Password123” get different fingerprints in the database. Without salt, an attacker can use pre-calculated lists of common hashes to crack thousands of accounts at once. Why let that happen? Salt forces them to start from zero for every single user.
Moving from simple encryption to salted, slow hashing changes the philosophy. The goal isn’t just to hide the password. It’s about making it too expensive to guess. Since no system is perfectly impenetrable, you just make the attack too slow to work.
If you manage user data, don’t invent your own scrambling methods, and use a dedicated hashing algorithm like Argon2 or bcrypt. Those tools handle salting and slowing automatically. Just make sure the cost factor is high enough to stop modern hardware but low enough that your users don’t feel the lag when they log in.
Frequently asked questions#
What is the difference between hashing and encryption?
Encryption is a two-way process using keys to lock and unlock data, allowing original text recovery. Hashing is a one-way function that creates a unique digital fingerprint. Because hashes cannot be reversed to reveal the original password, this method provides superior security for storing user credentials in a database compared to encryption.
Why are passwords hashed instead of encrypted?
Encrypting passwords requires storing a decryption key. If an attacker steals both the database and the key, every account is compromised immediately. Hashing avoids this risk by storing only fingerprints. The system compares hashes during login without ever needing to store or know the plain text password, removing the single point of failure.
How do slow hash functions stop attackers?
Fast hashing allows attackers to guess millions of passwords per second using powerful hardware. Slow hash functions force computers to perform thousands of internal loops before producing a result. While this delay is unnoticeable for a single user, it makes brute-force attacks practically impossible by turning hours of work into centuries of computation.