← Back to section · Foundations of Cryptography
Slow Hashing and Password Storage: Why a Stored Password Hash Must Be Deliberately Slow
Ordinary hashes are designed to be fast; password storage needs exactly the opposite — slow, memory-hungry, and salted per user. This article explains how the offline-cracking threat model shaped bcrypt, scrypt and Argon2. Principles only; the hands-on implementation lives in the tutorials section.
The word “hash” pursues opposite virtues in two settings. File checksums want a hash as fast as possible, ideally keeping up with the disk; password storage must be deliberately slow — slow enough that a legitimate user barely notices at login, yet painful when an attacker guesses in bulk. This article explains the reasoning behind that slowness: what the threat model is, what salt actually defends against, and how the bcrypt–scrypt–Argon2 lineage of password hashing functions raised the price across generations of hardware arms race. Working code belongs to the hands-on domain — the tutorials section has a dedicated Python article — so here we stay with principles.
The threat model: the database is already gone
Password storage starts from a pessimistic assumption: the database of hash values will eventually be stolen. Large password-database breaches have happened again and again, and once the attacker holds the hash file, the battle moves to their own machine room: no login rate limits, no captchas, just raw compute. Human passwords also carry strikingly low entropy — most people’s choices fall within the range an attacker’s dictionary and mangling rules try first. The economics of attack and defence are then stark: the defender computes the hash once per login, and 100 milliseconds is imperceptible; the attacker must try billions of candidate passwords, and doubling the per-guess cost multiplies the total bill by billions. The entire design of password hashing is about inflating that single-guess cost. Storing passwords with a plain fast hash (bare SHA-256, say) reduces that cost to nearly zero: a modern GPU computes billions per second, and an ordinary password falls within minutes.
Salt: making everyone’s lock different
The second component is salt: a random value generated per user, fed into the hash together with the password, and stored in plaintext in the database alongside the result. Beginners often assume the salt must be secret; its real job is not secrecy but de-batching. Without salt, users sharing a password share a hash, so one dictionary run hits all of them at once, and precomputed rainbow tables can simply be looked up. With an independent salt per user, two users with the same password have unrelated hashes; precomputation stops paying off for any individual user, and the attacker is forced back to guessing account by account. Salt should be long enough and truly random, but it need not be secret — it defends against economies of scale, not against a single attack.
Setting the parameters: spending a latency budget
Slow-hash parameters are not “the bigger the better”; they are a budget problem. The only currency the defender can spend is the delay a legitimate user will tolerate at login: common practice targets a few hundred milliseconds per verification — imperceptible to the user, sustainable for the server’s CPU at normal login volumes — and derives the iteration count and memory parameters backwards from that. Memory parameters must also reckon with concurrency: every login request occupies its own large block of memory, so at peak login load the total footprint grows in step, and an oversized parameter can drag your own service down — even handing denial-of-service attackers a lever. Most importantly, parameters must be upgradeable and actually revisited: hardware gets cheaper every year, and parameters that were safe three years ago may be discounted today. Mature storage formats (such as the PHC string format) encode the algorithm name, parameters and salt into the stored value itself, so verification uses the parameters recorded with each entry, and a successful login can quietly re-store the hash under fresh parameters — painless rolling upgrades. Systems that hard-code parameters in code and store bare values tend to pay dearly at some forced migration.
One more concept is often confused with salt: the pepper — a site-wide secret that is not kept in the database but in application configuration or a hardware security module, and that takes part in the password hash computation. Its division of labour with salt differs: salt defeats batching and precomputation, while pepper defends against the specific case of “only the database leaked” — holding the database alone, without the pepper, the attacker cannot even begin guessing. But it adds a key-management burden: lose the pepper and no password in the database can ever be verified. It is therefore an optional hardening, not a necessity; most systems capture the bulk of the benefit by getting salt and slow hashing right first.
Three price dimensions and three generations
On top of “slow”, designers gradually realised that CPU time alone is not enough: an attacker’s GPUs and ASICs carry thousands of parallel cores, and pure iteration is heavily discounted on such hardware. Pricing therefore expanded along three dimensions. Time cost: a tunable iteration/round parameter, so the cost of one computation can be raised periodically as hardware improves. Memory cost: requiring the computation to occupy a large block of memory — memory area cannot be stacked as cheaply as compute cores, and this dimension specifically blunts the parallel advantage of GPUs and ASICs. Parallelism: letting the legitimate server use multiple cores without granting the attacker an extra discount.
Three representative functions map exactly onto this evolution. bcrypt (1999) established the paradigm of a tunable cost parameter with built-in salt, but uses little memory. scrypt (2009) first brought memory-hardness into the mainstream, with parameters tuning time and memory separately. Argon2 (winner of the 2015 Password Hashing Competition) further distinguishes Argon2d (side-channel resistant), Argon2i (GPU-cracking resistant), and the hybrid Argon2id as the general recommendation — the first choice named by RFC 9106. The current consensus on selection is brief: default new systems to Argon2id, calibrate parameters to a “a few hundred milliseconds per login” budget on your own servers and revisit as hardware improves; existing bcrypt/scrypt deployments at sane parameters remain serviceable, with no need for panic migration. One boundary worth restating: slow hashing buys time after the database is lost. It replaces neither transport encryption, login rate limiting, nor multi-factor authentication — in a defence in depth, it is only the innermost door.
Tags: Password StorageArgon2Slow Hashing