Model NITI Aayog, 24-27 Dec, online. Write an original white paper.

How Does a Website Store Passwords Safely? | How It Works

12 min read

On this page

What is the short answer?

A website never needs to keep the student's password. It needs only to check that the password typed at login matches the one chosen at sign-up. So a well-built site stores a password hash: the output of a one-way function that is quick to compute but impractical to reverse.

A random salt, different for every user, is mixed in first, so two people with the same password get different hashes. A slow password-hashing function then makes every guess expensive.

In the United States, NIST's 2025 digital identity guidelines say passwords shall be salted and hashed. In the United Kingdom, guidance from the National Cyber Security Centre (NCSC), reviewed in 2018, says passwords should be stored hashed, with a salt and multiple rounds of the hash function.

Definition: NIST, the US standards agency, defines a cryptographic hash function as one that maps a bit string of any length to a fixed-length bit string. Approved hash functions are one-way: it is computationally infeasible to find an input that gives a chosen output.

What does a hash function do to a password?

A hash function takes any string of bits, a short password or a whole book, and returns an output of one fixed size. SHA-256, part of NIST's Secure Hash Standard, FIPS 180-4 of August 2015, always gives 256 bits, usually written as 64 hexadecimal characters.

NIST lists three properties of an approved hash function:

  • Preimage resistance: given an output, finding any input that produces it is infeasible. This is the one-way property.
  • Second preimage resistance: given one input, finding a different input with the same output is infeasible.
  • Collision resistance: finding any two different inputs with the same output is infeasible.

The University of California, Berkeley's computer security textbook adds that a small change to the input changes many bits of the output, with no detectable pattern. Computed with SHA-256, "sunflower" gives an output beginning 8f398886c326, and "Sunflower" one beginning 875af21cd687. One capital letter changes 131 of the 256 bits.

Why are plain text and a plain fast hash both unsafe?

The Berkeley textbook calls storing passwords as typed bad for security: if the site is hacked and its database copied, every password is exposed at once, and people who reuse passwords are exposed on other sites too. The NCSC tells system owners to make sure systems "do not store passwords as plain text".

Encryption does not solve the problem. The OWASP Foundation, a non-profit that publishes software security guidance, explains that encryption is a two-way function, so attackers can retrieve the original plain text from encrypted data. A hash, being one-way, cannot be decrypted.

A plain hash leaves two gaps. First, SHA-256 is built to be fast: OWASP says such fast algorithms are not suitable for password storage because they allow large numbers of guesses quickly, and NIST notes that attackers can compute many billions of hashes per second offline.

Second, identical passwords give identical hashes. A stolen list then shows which users share a password, and work done on one of those hashes applies to all of them.

What does a salt add?

A salt is a random value created for each user and combined with the password before hashing. The Berkeley textbook explains that its only purpose is to be different for each user. It need not be secret, and it is stored in the clear beside the hash.

Salts change two things. Users with the same password get different hashes, so a stolen list no longer reveals who shares one. And a precomputed table of hashes for common passwords stops working, because it would have to be rebuilt for every salt; OWASP says salting protects against such pre-computed hashes.

NIST sets a floor: the salt shall be at least 32 bits long and chosen to keep repeated salts to a minimum. RFC 9106, the Argon2 specification, recommends 128 bits. A salt does not make a weak password strong; it stops one piece of work from unlocking many accounts.

How do slow, memory-hard functions raise the cost of each guess?

A password-hashing function is slow on purpose, with a cost factor that sets the work per hash. NIST says the cost factor should be as high as practical without hurting the site's performance.

  • bcrypt was presented in June 1999 by Niels Provos and David Mazières of the OpenBSD Project, at a USENIX conference in Monterey, California. Their paper argued that a password scheme's cost must rise as hardware improves.
  • scrypt, presented by Colin Percival in May 2009, is memory-hard: it needs a large block of memory as well as time. RFC 7914 of August 2016 says this adds protection against attacks using custom hardware.
  • Argon2 won the Password Hashing Competition, an open contest that ran from 2013 to 2015; the winner was announced in July 2015. RFC 9106 of September 2021, two of whose authors list the University of Luxembourg, calls it a memory-hard function for password hashing.

NIST also recommends a further step, which OWASP calls a pepper: keyed hashing or encryption with a secret key known only to the site, stored apart from the hashes. OWASP says a pepper protects the hashes when attackers obtain only the database.

How does a login check work, step by step?

  1. Sign-up: the site creates a fresh random salt for the new user.
  2. Hashing: it runs the chosen password and the salt through its password-hashing function.
  3. Storage: it saves the user name, the salt and the resulting hash, and keeps no copy of the password.
  4. Login: when someone types a password, the site fetches that user's salt and stored hash.
  5. Recomputing: it hashes the typed password with the same salt and function.
  6. Comparing: a match means the password was right; otherwise the attempt fails and is counted.

The site never reverses a hash; it repeats the calculation and compares, as the Berkeley textbook describes. NIST adds rules: the site shall verify the entire password without cutting it short, and shall not let users store a hint that someone not logged in can see.

What does a leak expose, and what else do named bodies describe?

A leak of plain text exposes every password at once. A leak of hashes, NIST explains, allows an offline attack: guesses tested against the stolen hashes on other machines, beyond the reach of throttling, which NIST calls the primary defence against online attacks.

The NCSC warns that some passwords may be recovered if they were hashed poorly or the attacker has enough computing power.

  • Rate limiting: NIST allows no more than 100 consecutive failed attempts with one password before it is disabled.
  • Blocklists: NIST says new passwords are compared against a blocklist of commonly used, expected or compromised passwords.
  • Length: NIST requires at least 15 characters for a password used alone, and allows 8 when it is one part of multi-factor authentication.
  • Multi-factor authentication: in NIST's terms, this combines two distinct factors from something the user knows, has or is. The NCSC says MFA makes a compromised password less useful to an attacker.
  • After a breach: NIST says a site shall force a password change when there is evidence of compromise.

Where do named bodies differ?

Which slow function do they point to?

  • OWASP lists Argon2id first, then scrypt; bcrypt only for older systems lacking both; and PBKDF2 built on SHA-256, at 600,000 or more iterations, where FIPS-140 compliance is required.
  • NIST says in its July 2025 guidelines that an approved scheme from its SP 800-132 or updated NIST guidelines should be used.
  • The NCSC said in guidance reviewed in November 2018 that hashing should follow public standards, naming PBKDF2.
  • The Crypto Forum Research Group of the Internet Research Task Force, a research body, recommends Argon2id in RFC 9106.

How many failed logins before an account is locked?

  • NIST sets 100 consecutive failures as an upper bound, and says agencies may set lower limits.
  • The NCSC prefers throttling, a growing delay between attempts, because lockout can shut out genuine users. Where lockout is used, it recommends allowing 5 to 10 attempts.

On two points the agencies agree. NIST says sites shall not require periodic password changes or impose composition rules such as mixing character types; the NCSC advises against regular expiry and complexity requirements.

How does this work with real numbers?

Why do salts help on a site with 1,000,000 users?

Take an illustrative site with 1,000,000 users, of whom 10,000 chose the same common password.

  • Share: 10,000 ÷ 1,000,000 = 1% of users have that password.
  • No salt: the same input gives the same hash, so the list holds 10,000 identical entries. One computed hash can be compared with all of them at once.
  • Salted: each user has a different salt, so the 10,000 entries are all different. Checking one guess against them takes 10,000 separate hash computations, one per salt.
  • Salt size: with 128-bit salts, as RFC 9106 recommends, there are 2¹²⁸, about 3.4 × 10³⁸, possible values; the 10,000 users form 10,000 × 9,999 ÷ 2 ≈ 5.0 × 10⁷ pairs, so a shared salt is vanishingly unlikely.

Why does slow hashing help?

Suppose, illustratively, that checking one guess takes 1 microsecond with a fast hash and 100 milliseconds with a slow password hash.

  • Fast hash: 1 second ÷ 0.000001 second = 1,000,000 guesses a second.
  • Slow hash: 1 second ÷ 0.1 second = 10 guesses a second.
  • Ratio: 1,000,000 ÷ 10 = 100,000 times fewer guesses in the same time.
  • One million guesses: 1,000,000 × 0.000001 = 1 second with the fast hash, but 1,000,000 × 0.1 = 100,000 seconds, about 27.8 hours, with the slow one.

The real user waits 0.1 second once, at login. With salts, the slow cost applies separately to every account in a stolen list.

Where can the student go deeper in World 101?

The World 101 subject Cybersecurity covers the wider field: protecting digital systems and information from disruption, misuse and unauthorised access, and restoring them when defences fail. Salting, slow hashing and limits on login attempts are a small part of that work.

Three related subjects go further. Cryptography & Digital Security studies secure communication and data protection, including the mathematical hardness assumptions that make functions such as SHA-256 hard to reverse. Computing Fundamentals explains how computers process information through algorithms, hardware and software, the machinery on which every hash is computed. Data Privacy Law looks at the rules on how governments, companies and other organisations collect, store and use personal information, and how those approaches vary around the world.

Sources

  • NIST, SP 800-63B-4, "Digital Identity Guidelines: Authentication and Authenticator Management", July 2025 (HTML edition), read 18 November 2026.
  • NIST Computer Security Resource Center, "Hash Functions" project page, updated 16 September 2026, and glossary entry "cryptographic hash function", read 18 November 2026; FIPS 180-4, Secure Hash Standard, August 2015.
  • UK NCSC, "Password policy: updating your approach", reviewed 19 November 2018.
  • OWASP Foundation, Password Storage Cheat Sheet, read 18 November 2026.
  • University of California, Berkeley, CS 161 textbook "Computer Security", chapters on cryptographic hashes and passwords, read 18 November 2026.
  • N. Provos and D. Mazières, "A Future-Adaptable Password Scheme", 1999 USENIX Annual Technical Conference, Monterey, California, June 1999.
  • C. Percival and S. Josefsson, RFC 7914, the scrypt function, IETF, August 2016 (citing Percival's paper of May 2009).
  • Password Hashing Competition, password-hashing.net (ran 2013 to 2015; Argon2 announced July 2015), read 18 November 2026.
  • A. Biryukov and others, RFC 9106, Argon2, IRTF Crypto Forum Research Group, September 2021.

Common errors and misconceptions

  • Misconception: A site that stores passwords well can send a forgotten password back. Correct: A salted hash is one-way, so the site cannot recover the password, only let the user set a new one.
  • Misconception: Hashing a password is the same as encrypting it. Correct: OWASP explains that encryption is two-way, so the original can be retrieved, while a hash cannot be decrypted.
  • Misconception: Any well-known hash, such as SHA-256, is fine for passwords. Correct: OWASP says fast hashes such as SHA-256 are unsuitable because they allow many guesses quickly.
  • Misconception: A salt must be kept secret to work. Correct: The salt is stored in the clear beside the hash; its job is to differ for every user.
  • Misconception: Once passwords are hashed, a leak does no harm. Correct: NIST says leaked hashes allow offline guessing, and the NCSC warns that some passwords may be recovered.

Key takeaways

  • A website checks a password by recomputing a one-way hash and comparing it with the stored one, so it never needs to keep the password.
  • NIST describes approved hash functions as giving a fixed-length output that is infeasible to reverse; SHA-256 always gives 256 bits.
  • Plain text exposes every password in a leak, and an unsalted hash makes identical passwords show up as identical entries.
  • A random salt for each user, at least 32 bits under NIST's guidelines, makes identical passwords hash differently and defeats precomputed tables.
  • Slow functions such as bcrypt, and memory-hard scrypt and Argon2, the 2015 Password Hashing Competition winner, make each guess costly.
  • NIST and the NCSC also describe rate limits, blocklists, multi-factor authentication and forced changes after a compromise, while differing on lockout limits.

Test yourself

How can a site check a password without storing it?

It stores a salted hash; at login it hashes the typed password with the same salt and compares the results.

What does "one-way" mean for a hash function?

Given an output, finding any input that produces it is computationally infeasible, so the hash cannot practically be reversed.

Why is SHA-256 alone unsuitable for storing passwords?

OWASP says fast hashes allow large numbers of guesses quickly, and without salts identical passwords give identical hashes.

What two things does a salt change?

Users with the same password get different hashes, and precomputed tables of hashes stop working, since each salt needs its own.

In the illustrative example, how many guesses fit in one second with each hash?

1,000,000 with a 1 microsecond fast hash, and 10 with a 100 millisecond slow hash: 100,000 times fewer.

How do NIST and the NCSC differ on failed logins?

NIST sets an upper bound of 100 consecutive failures; the NCSC prefers throttling and, where lockout is used, recommends 5 to 10 attempts.

Curious Computing: how computers, code and the internet work.

Go deeper in World 101: Cybersecurity

Write about it

Turn a question from this chapter into a paper.

The Writing Studio has a structure guide, a rubric and citation tools for 15 formats, from essays to research papers. A free account keeps up to five drafts. Learnacy Essential adds feedback from an AI writing coach and submission to The OYI Review.

Publication depends on review and is not guaranteed.