In short
A password should never be stored in a form that can be reversed back into the original text, which is why systems store a hash rather than the password itself. A cryptographic hash function is one-way by design, but a bare hash is still vulnerable to precomputed lookup tables and to brute-force guessing at high speed, which is why real systems add a unique salt per password and use deliberately slow, memory-hard algorithms such as bcrypt or Argon2. The choice of algorithm and its cost parameters is a direct, measurable trade-off between attacker cost and legitimate login latency.
When a service is breached and a database of user credentials leaks, the difference between a catastrophe and a manageable incident usually comes down to one design decision made long before the breach: how passwords were stored. Storing a password in plain text, or in a form that can be decrypted back to plain text, turns any database leak into an immediate full account compromise for every affected user. Password hashing exists specifically to prevent that outcome.
Hashing is not encryption
Encryption is deliberately reversible: given the right key, ciphertext can be turned back into plaintext, because encryption exists to protect data that legitimately needs to be recovered later. A password, by contrast, never needs to be recovered by the system storing it — the system only ever needs to check whether a freshly entered password matches the one originally set. A cryptographic hash function is built for exactly that one-way relationship: it is computationally infeasible to reconstruct the input from the output, but trivial to check whether a given input produces a known output.
This is why storing an encrypted password, even with strong encryption, is worse practice than hashing it: encryption implies a key exists somewhere that can reverse it, and if that key is ever exposed alongside the database, every password is recovered instantly. A properly hashed password has no such key to steal.
Why a bare hash still fails
Precomputed lookup tables
If two users choose the identical password, a bare, unsalted hash function produces the identical output for both, immediately revealing the match to anyone with the database. Worse, attackers can precompute hashes for enormous lists of common passwords in advance — a rainbow table — and simply look up any leaked hash against that table, turning what should be an expensive attack into a fast dictionary lookup.
Raw computational speed
General-purpose cryptographic hash functions such as SHA-256 are designed to be fast, because their usual job is verifying file integrity or building other cryptographic protocols, where speed is a virtue. That same speed is a severe liability for password storage: modern GPU hardware can compute billions of SHA-256 hashes per second, meaning a leaked database of SHA-256 password hashes can have a large fraction of its weak and moderately strong passwords guessed within hours.
Salting: defeating precomputation
A salt is a random value generated uniquely for each password and stored alongside its hash (it does not need to be secret). The salt is combined with the password before hashing, so two identical passwords with different salts produce completely different hashes. This defeats precomputed lookup tables outright, since an attacker would need a separate precomputed table for every possible salt value, which is computationally infeasible at any reasonable salt length.
- Salts must be unique per password, not shared across an entire system, or the precomputation defence collapses back to a single table.
- Salts do not need to be kept secret; their purpose is uniqueness, not confidentiality, so storing them in plain text next to the hash is standard and safe.
- Modern password hashing algorithms handle salt generation and storage automatically as part of their standard output format.
- A salt does not slow down an individual guess; it only prevents reusing work across multiple targets.
Slowness and memory cost as deliberate defences
Salting stops precomputed attacks but does nothing to slow down an attacker guessing one specific salted hash at a time. That is the job of the second design principle: the hashing function itself must be slow and, ideally, memory-hungry, on purpose. Algorithms purpose-built for password storage — bcrypt, scrypt and Argon2 — include a tunable cost or work factor that deliberately makes each individual hash computation take a meaningful fraction of a second rather than a fraction of a microsecond.
This trade-off is easy to state precisely: a legitimate login only ever needs one hash computed, so a hash that takes 100 milliseconds is invisible to a real user, while an attacker needing to try billions of guesses sees that 100 milliseconds multiplied across every single attempt. Memory-hardness adds a second dimension: Argon2 and scrypt require substantial memory per computation, which sharply limits how much an attacker's specialised parallel hardware — GPUs and custom chips excel at fast, low-memory operations — can accelerate the attack, unlike raw CPU-speed-only algorithms.
| Algorithm | Memory-hard | Tunable cost | Typical current guidance |
|---|---|---|---|
| MD5 / SHA-1 / SHA-256 (bare) | No | No | Never use alone for password storage |
| PBKDF2 | No | Yes (iteration count) | Acceptable where FIPS compliance is required; use a high iteration count |
| bcrypt | Limited | Yes (work factor) | Widely supported, solid default choice |
| scrypt | Yes | Yes (CPU/memory/parallelism) | Good where memory-hardness matters and library support exists |
| Argon2id | Yes | Yes (memory, iterations, parallelism) | Current OWASP-recommended default |
Illustrative time to test one billion guesses
Approximate time, illustrative figures on commodity GPU hardware
Figures are order-of-magnitude illustrations to show relative resistance, not measured benchmarks; actual attacker throughput depends heavily on hardware, parallelism and chosen cost parameters.
Setting cost parameters in practice
Cost parameters are not a one-time decision; hardware gets faster every year, so a work factor considered strong in 2018 is weaker relative to attacker capability today. Current OWASP guidance recommends selecting Argon2id parameters (or bcrypt's work factor, where Argon2 is unavailable) such that a single hash computation takes on the order of a few hundred milliseconds on production hardware, then re-evaluating that figure periodically as hardware improves.
- Choose Argon2id where the platform and libraries support it; fall back to bcrypt where they do not.
- Set the cost parameter so a single hash takes roughly 250 to 500 milliseconds on the server's actual production hardware, not a developer laptop.
- Never write custom hashing logic; use a well-reviewed library that handles salt generation, encoding and parameter storage automatically.
- Re-hash and upgrade stored passwords opportunistically at next login when cost parameters or algorithms are increased.
- Rate-limit and monitor login attempts as a complementary control, since hashing cost alone cannot fully stop online guessing against a live login endpoint.
Increasing the cost factor
Pros
- Directly and measurably increases the computational cost of an offline brute-force attack against leaked hashes
- Requires no change to user experience, since the added delay is a fraction of a second per login
- Memory-hard algorithms specifically blunt the advantage of GPU and ASIC-based cracking hardware
Cons
- Higher cost parameters increase server CPU and memory load at login time, which matters at very high login volumes
- Overly aggressive settings can create a denial-of-service risk if an attacker can trigger many hash computations cheaply
- Existing stored hashes must be migrated gradually, since changing the cost parameter does not retroactively rehash old data
Key points
- Passwords should be hashed, never encrypted, because hashing has no key that can be stolen to reverse it.
- A unique salt per password defeats precomputed lookup table attacks by making identical passwords hash differently.
- General-purpose fast hash functions like SHA-256 are unsuitable for passwords precisely because their speed helps attackers.
- Argon2id and bcrypt are deliberately slow and, in Argon2's case, memory-hard, to raise the cost of brute-force guessing.
- Cost parameters must be re-evaluated periodically as hardware gets faster, not set once and forgotten.
A short history: from crypt() to purpose-built algorithms
Early Unix systems introduced the crypt() function in the 1970s, which hashed passwords using a variant of the Data Encryption Standard run 25 times, with a 12-bit salt to blunt precomputation. It was a genuine advance for its era, but a 12-bit salt allows only 4,096 distinct values, which is small enough that an attacker can precompute a lookup table for every possible salt without much difficulty by modern standards, and the fixed 25 iterations became trivially fast as processors improved. By the 1990s, MD5-crypt and later bcrypt were developed specifically to address these two weaknesses: larger, effectively unguessable salts and a work factor that could be increased over time as hardware improved. That second property — tunability — is arguably the more important of the two, because it converts password hashing from a one-off design decision into an ongoing operational practice that has to be revisited as computing power grows.
Timing attacks and constant-time comparison
A subtler failure mode than the choice of hashing algorithm itself is how the computed hash is compared against the stored one. A naive string comparison function typically returns as soon as it finds the first mismatched character, which means a wrong guess that happens to share its first few characters with the correct hash takes microseconds longer to reject than one that differs immediately. Measured over enough attempts, sent across a network, that timing difference can in principle leak information about the correct value one byte at a time — a timing side-channel attack. Well-designed authentication libraries use a constant-time comparison function instead, one that always examines every byte regardless of where a mismatch occurs, so that the time taken reveals nothing about how close a guess was. This is a small implementation detail with an outsized consequence: an otherwise correctly salted and slowly hashed password check can still leak information if the final comparison step is written carelessly.
Where password hashing sits next to other authentication secrets
It is worth being precise about what password hashing does and does not overlap with. Time-based one-time passcodes, the six-digit codes generated by an authenticator app as part of multi-factor authentication, are not hashed in the same sense at all — the server needs the original shared secret to compute the expected code for comparison, so that secret is typically stored encrypted, with the encryption key held separately, rather than hashed one-way like a password. Session tokens and API keys occupy a middle ground: a well-designed system stores only a hash of a long-lived API key, exactly as it would a password, precisely because a leaked database should not hand an attacker a working credential. Recognising which category a given secret falls into — is it checked by comparison to a hash, or does the server need to reconstruct or decrypt it — is the first question to ask before deciding how to store it.
Common implementation mistakes that undermine good algorithm choice
Choosing Argon2id is necessary but not sufficient; a surprising share of real-world weaknesses come from how the surrounding system is built rather than from the algorithm itself. Truncating a very long password before hashing, for instance, silently discards entropy the user believed they were contributing. Failing to enforce a reasonable minimum length allows the strongest hashing algorithm in the world to protect a password an attacker can simply guess online in a handful of attempts. Logging the plaintext password anywhere in the request pipeline — in application logs, error reports or analytics events — defeats the entire exercise regardless of how the database stores it, because the exposure happens before hashing is even reached. And storing password reset tokens or verification codes without their own hashing, on the assumption that they are short-lived and therefore lower risk, has repeatedly been the actual point of compromise in publicised incidents, even when the main password table was hashed correctly.
- Enforce a sensible minimum length rather than complex character-class rules, which research has shown do little to stop guessing while frustrating legitimate users.
- Never truncate a password silently before hashing; if a maximum length is required for practical reasons, reject overlong input explicitly instead.
- Hash password reset tokens and email verification codes the same way as passwords, since they grant equivalent account access if intercepted.
- Audit logging pipelines specifically for accidental plaintext capture of authentication fields, which is a recurring, low-visibility source of real breaches.
Sponsored video
AdvertisementChecking for a video ad…
Frequently asked questions
Sources
- OWASP Password Storage Cheat Sheet — OWASP Foundation
- RFC 9106: Argon2 Memory-Hard Function for Password Hashing and Proof-of-Work Applications — IETF
- Digital Identity Guidelines: Authentication and Lifecycle Management (SP 800-63B) — NIST
- bcrypt — OpenBSD Project (original bcrypt specification and reference)
About the author
Michael Adeyemi — Senior Technology Writer
Michael writes Inquro's computing and web-infrastructure coverage. He worked for eight years as a platform engineer on high-traffic content systems before moving into full-time technical explanation, and he still prototypes every measurement described in his articles before publishing the numbers.
- Qualifications
- MSc, Distributed Systems — University of Manchester
- BEng, Computer Engineering — University of Lagos
- Experience
- Eight years as a platform engineer on high-traffic content delivery systems
- Four years writing standards-based technical documentation
- Subject areas:
- Web performance, Networking, Systems architecture
- Contact:
- michael@inquro.example
Reviewed for factual accuracy by Dr. Rina Halvorsen, Editor-in-Chief (PhD, Cognitive Science), on 19 March 2026.
Structure, claim strength and whether an explanation actually answers the question a reader arrived with.
Inquro articles are commissioned, sourced, reviewed and re-checked under a published editorial policy. Corrections are made in place and dated — write to editorial@inquro.example if you find an error.






