Password Password

Security, explained for the people who have to fix it.

Passwords and Auth

How password hashing works: bcrypt, scrypt, Argon2, and the salt

What a verifier stores instead of your password, why bcrypt, scrypt and Argon2 are slow on purpose, and why the salt is not a secret.

If you run a login form, the thing you store is not the password. It is the output of a deliberately slow function of the password and a random value, and the whole design exists for one day you hope never comes: the day someone copies your user table. This article explains what that function does, why the three names you keep hearing (bcrypt, scrypt, Argon2) are slow on purpose, why the salt sitting next to the hash in plain view is fine, and which parameters the published guidance actually names. Nothing here helps anyone attack a table they stole; all of it helps you make the table not worth stealing.

What a verifier needs to store

A verifier has one job at login: decide whether the string the user just typed is the same string they registered with. It does not need the original string to do that. If you store H(password) for some one-way function H, you can recompute H(typed) and compare. A plain cryptographic hash like SHA-256 satisfies "one-way" but fails the real requirement, because it is fast. Fast is exactly the property an attacker with a stolen table wants: they guess candidates, hash each one, and compare against every row.

So the function has to be slow, and slow in a way that does not get cheaper on specialised hardware. NIST SP 800-63B (the 2025 revision, Section 3.1.1.2) puts it as a requirement: memorized secrets "SHALL be salted and hashed using a suitable password hashing scheme", the salt "SHALL be at least 32 bits in length and chosen to minimize salt value collisions", and the cost factor "SHOULD be as high as practical without negatively impacting verifier performance". Both the salt and the hash are stored for each password.

Why the salt is not a secret

The salt does two things, and neither requires it to be hidden.

First, it makes identical passwords produce different stored values. Without a salt, every user with the same password has the same hash, and one guess that matches one row matches all of them. With a per-user random salt, the attacker has to run the slow function once per row per guess. Second, it defeats precomputation. A table of hashes computed in advance for common passwords is useless if every stored hash also depends on a value the attacker did not know when they built the table.

Both effects come from the salt being unique and unpredictable, not from it being confidential. The password-hashing functions below take the salt as an input and emit it as part of their output string, in the clear. That is by design. If your threat model needs a secret, that is a separate ingredient: OWASP calls it a pepper, a value "shared between stored passwords" that "should not be stored along with the generated hash". NIST describes the same idea as an additional keyed iteration with a key that "SHOULD be stored and used within a hardware-protected area, such as a hardware security module". A pepper helps when the database leaks but the application server does not. It does not replace the salt.

bcrypt: old, still fine, with a 72-byte catch

bcrypt (1999) runs a modified Blowfish key schedule for 2^cost rounds. The cost is a small integer; each increment doubles the work. OWASP's current guidance is that "the work factor should be as large as verification server performance will allow, with a minimum of 10", and it now lists bcrypt under legacy systems rather than as the first choice.

The catch every implementer should know is the input limit: "bcrypt has a maximum input length of 72 bytes". Bytes, not characters. Longer inputs are silently truncated in most implementations, which means two different long passwords can verify as the same one. OWASP's advice is to enforce a maximum password length of 72 bytes when bcrypt is in use, rather than pre-hashing, which introduces its own pitfalls.

scrypt: the first memory-hard design

bcrypt's work is compute-bound, and compute is what GPUs and ASICs are good at. scrypt (2009) added a second dimension: it fills a large block of memory with pseudorandom data and then reads it back in a data-dependent order. An attacker who wants to run many guesses in parallel now needs many copies of that memory, which is where custom hardware loses its edge. OWASP's fallback parameters when Argon2id is unavailable are N=2^17 (128 MiB), r=8, p=1, "or other configurations providing equivalent security through different memory/parallelism tradeoffs".

Argon2id: the current recommendation

Argon2 won the Password Hashing Competition in 2015 and is specified in RFC 9106 (September 2021). The RFC describes it as "a memory-hard function" that "aims at the highest memory-filling rate and effective use of multiple computing units, while still providing defense against trade-off attacks". The id variant mixes data-independent and data-dependent memory access, which is why both OWASP and the RFC name it as the default.

RFC 9106 Section 4 gives two recommended settings: "Argon2id with t=1 iteration, p=4 lanes, m=2^(21) (2 GiB of RAM), 128-bit salt, and 256-bit tag size", and the lighter "t=3 iterations, p=4 lanes, m=2^(16) (64 MiB of RAM)". OWASP publishes a ladder of equivalent-strength settings for servers that cannot spare 2 GiB per login, from "m=47104 (46 MiB), t=1, p=1" down to "m=7168 (7 MiB), t=5, p=1", with a stated floor of "m=19456 (19 MiB), t=2, p=1".

Function Type of cost Reference setting Where the guidance puts it
Argon2id memory and time m=19 MiB, t=2, p=1 (OWASP minimum); m=64 MiB, t=3, p=4 (RFC 9106) first choice
scrypt memory and time N=2^17, r=8, p=1 when Argon2id is unavailable
bcrypt time cost >= 10, input capped at 72 bytes legacy systems
PBKDF2-HMAC-SHA256 time 600,000 iterations FIPS-140 environments

The PBKDF2 row exists because some compliance regimes require a FIPS-approved primitive; OWASP's iteration counts are 600,000 for SHA-256, 220,000 for SHA-512, and 1,400,000 for SHA-1 (legacy only).

Cost, measured

The guidance above names settings, not what they cost. We measured them with the hashing bench this site publishes (password-hash-bench.py, results in the Code and data box): one thread of a 13th Gen Intel Core i9-13900HX laptop processor, the median of 15 timed runs per setting, measured 2026-10-30. These are costs to the server that checks a password, on one ordinary CPU thread. We did not measure GPUs or the specialised hardware an attacker might use, and those rates would be different. "CPU threads for 100 logins a second" is the time per login times 100, rounded up; "logins that fit in 1 GiB" divides 1 GiB by the measured peak memory of one hash.

Function Setting OWASP list Time per login CPU threads for 100 logins a second Memory per login Logins in progress that fit in 1 GiB
Argon2id m=19 MiB t=2 p=1 OWASP 21.8 ms 3 18.3 MiB 55
Argon2id m=46 MiB t=1 p=1 OWASP 33.4 ms 4 45.3 MiB 22
Argon2id m=7 MiB t=5 p=1 OWASP 17.6 ms 2 6.3 MiB 162
scrypt N=2^17 r=8 p=1 OWASP 389.3 ms 39 128.1 MiB 7
scrypt N=2^13 r=8 p=10 OWASP alternative 212.1 ms 22 8.1 MiB 126
bcrypt cost 10 OWASP minimum 41.2 ms 5 not measured (compute-bound) n/a
bcrypt cost 11 not listed 99.8 ms 10 not measured (compute-bound) n/a
bcrypt cost 12 not listed 199.6 ms 20 not measured (compute-bound) n/a
bcrypt cost 13 not listed 399.1 ms 40 not measured (compute-bound) n/a
PBKDF2-HMAC-SHA256 600,000 iterations OWASP 198.8 ms 20 not measured (compute-bound) n/a

What the rows say, in the server's terms:

  • Argon2id at OWASP's floor (19 MiB, t=2) took 21.8 ms and 18.3 MiB per login. Keeping up with 100 logins a second takes 3 CPU threads, and 55 logins in progress at once fit in 1 GiB. The other ends of OWASP's ladder were 33.4 ms at 45.3 MiB (t=1) and 17.6 ms at 6.3 MiB (t=5): the ladder trades memory for passes, and on this processor the time stayed within a factor of two.
  • scrypt at N=2^17 is the expensive row: 389.3 ms and 128.1 MiB per login, 18 times the CPU time of the Argon2id floor. 100 logins a second need 39 threads, and only 7 fit in 1 GiB at once. OWASP's N=2^13, p=10 alternative cuts memory to 8.1 MiB but still took 212.1 ms.
  • bcrypt cost 10, OWASP's minimum, took 41.2 ms. Each cost step should double the work. From cost 10 to 13 the medians went x2.42, x2.00, x2.00 (x9.69 overall, against x8 in theory). The cost-11 median is the outlier: its fastest run was 82.3 ms, close to double cost 10 (82.4 ms), so the cost-11 median includes slower runs. Costs 12 and 13 took 199.6 ms and 399.1 ms.
  • PBKDF2-HMAC-SHA256 at 600,000 iterations took 198.8 ms, about the same as bcrypt cost 12, and it has no memory cost, so the iteration count is its only defence against parallel hardware.

None of these is too slow for a login, which happens once a session; they add up only for a service with very many logins at once, and the table shows the CPU and memory that takes. The milliseconds are this processor's; measure on your own hardware before choosing a setting.

The 72-byte limit, run

The same script runs bcrypt's input limit live, against bcrypt 5.0.0, the version the bench used. A password longer than 72 bytes is now refused with an error that suggests truncating by hand. If you do, two different passwords that share their first 72 bytes get the same hash, and each one verifies against the other's. The salt is fixed only so the output repeats; a real system uses a random salt per password. This is the script's real output:

bcrypt's 72-byte limit, live (bcrypt 5.0.0)
two passwords: 86 and 86 bytes, identical in the first 72 bytes, different after
hashpw(73+ bytes) -> ValueError: password cannot be longer than 72 bytes, truncate manually if necessary (e.g. my_password[:72])
after truncating by hand, as the message suggests:
  hash of password one: $2b$10$passwordpasswordcomde.oSpTX6qHgX31omWbio4c0FOihyXnUYW
  hash of password two: $2b$10$passwordpasswordcomde.oSpTX6qHgX31omWbio4c0FOihyXnUYW
  identical: True; checkpw(password two, hash one) -> True
characters that fit in 72 bytes of UTF-8:
  ASCII letter    1 byte(s) each -> 72
  accented Latin  2 byte(s) each -> 36
  Cyrillic        2 byte(s) each -> 36
  Chinese         3 byte(s) each -> 24
  emoji           4 byte(s) each -> 18

Older versions of the package truncated silently instead of raising the error, with the same result. The limit counts bytes of UTF-8, not characters: 72 ASCII letters, but 36 accented Latin or Cyrillic letters, 24 Chinese characters or 18 emoji. A form that caps password length in characters can still pass bcrypt more than 72 bytes, which is why OWASP's advice above is a byte limit.

A worked verification, with the salt in view

The standard library does not ship Argon2, so this listing uses hashlib.scrypt, which it does ship. The shape is the same for any of the three: generate a salt, run the slow function, store a string that carries the parameters, the salt, and the tag; at login, parse the string, rerun with the same parameters and salt, and compare in constant time.

import base64, hashlib, hmac, os

N, R, P = 2**17, 8, 1          # OWASP's scrypt fallback parameters (128 MiB)

def hash_password(password: str) -> str:
    salt = os.urandom(16)      # 128 bits; NIST's floor is 32 bits, more is free
    tag = hashlib.scrypt(password.encode(), salt=salt, n=N, r=R, p=P, maxmem=2**28, dklen=32)
    return "scrypt$%d$%d$%d$%s$%s" % (N, R, P, base64.b64encode(salt).decode(), base64.b64encode(tag).decode())

def verify(password: str, stored: str) -> bool:
    _, n, r, p, salt_b64, tag_b64 = stored.split("$")
    salt, tag = base64.b64decode(salt_b64), base64.b64decode(tag_b64)
    candidate = hashlib.scrypt(password.encode(), salt=salt, n=int(n), r=int(r), p=int(p), maxmem=2**28, dklen=32)
    return hmac.compare_digest(candidate, tag)

Look at what the stored string contains: the algorithm name, the three parameters, the salt, and the tag, all readable. An attacker who copies it learns exactly how much work each guess costs them. That is the point. Every real password-hashing library emits the same kind of self-describing string, because carrying the parameters is what lets you raise them later.

Raising the cost over time

Hardware gets faster, so a cost that was right in 2019 is light now. Because the parameters travel with the hash, you can upgrade lazily: at each successful login you already have the plaintext for a moment, so if the stored parameters are below your current policy, rehash with the new ones and overwrite. Users who never log in keep the old hash, which is a reason to have an expiry for dormant accounts rather than a reason to avoid upgrading.

A legacy table of unsalted fast hashes can be wrapped rather than waited out: compute Argon2id(old_hash) for every row now, mark the rows as wrapped, and unwrap to a direct Argon2id hash at next login. OWASP describes this pattern for upgrading legacy hashes. It closes the fast-hash exposure immediately instead of at the user's convenience.

What to do

  • Pick Argon2id, at or above OWASP's minimum of 19 MiB and t=2, and measure the login latency on your real hardware before settling. If the library is unavailable, scrypt at N=2^17; bcrypt only where you already have it, with a 72-byte input cap.
  • Generate a 16-byte random salt per password from the operating system's CSPRNG, store it beside the hash, and do not treat it as a secret.
  • Add a pepper only if it lives somewhere the database does not, and rotate it with a plan for rehashing.
  • Compare tags with a constant-time function, as the listing does with hmac.compare_digest.
  • Store the parameters with the hash, set a policy version, and rehash on login when the stored parameters fall below it.
  • Remember what hashing does not do: it does not stop credential stuffing with passwords stolen from somewhere else, and it does not stop a weak password from being guessed in a handful of tries. Those need a blocklist and rate limiting, which NIST covers in the same section, and which the entropy article on this site takes up next.

The limitation to state plainly: slow hashing buys time, measured in attacker cost per guess. It does not make a password that is on every guess list survive. For those, the only fix is not to allow them in the first place.

Update, 4 November 2026: added "Cost, measured": time and memory per login for each setting, from our hashing bench, and a live run of bcrypt's 72-byte limit, with the script behind both. The rest of the article is unchanged.

Everything on this site is written for defenders and for people securing systems they own or are authorised to test. It describes how attacks work so they can be recognised and closed; it is not a guide to accessing anyone else's systems.

Sources

  1. OWASP, "Password Storage Cheat Sheet"
  2. IETF, RFC 9106 "Argon2 Memory-Hard Function for Password Hashing and Proof-of-Work Applications" (September 2021)
  3. NIST, SP 800-63B "Digital Identity Guidelines: Authentication and Authenticator Management" (Section 3.1.1.2, Memorized Secret Verifiers)
  4. pyca, "bcrypt" Python package (version 5.0.0, used for the 72-byte run)