What k-anonymity is, and why your password checker should use it

Every "is my password leaked?" service faces the same contradiction: to answer, it needs to compare your password with a database of leaked ones; to stay trustworthy, it must never learn your password.

K-anonymity is the property that resolves it. Instead of asking "is this password in the list?", you ask "give me everything in the same neighbourhood, and I'll check locally". The server answers a question about a group, and learns nothing about the individual.

The construction

  1. Hash the password with SHA-1 in the browser.
  2. Split the 40-character hex hash into a prefix (first 5 characters) and a suffix (the remaining 35).
  3. Send only the prefix to api.pwnedpasswords.com/range/{prefix}.
  4. The server returns every hash in its database starting with that prefix — usually several hundred, each with a count of how often it appeared in breaches.
  5. Compare the suffixes locally. A match means the password is in the data, with its breach count.
5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8
└───┘ sent
     └──────────────────────────────────┘ never leaves the browser

The prefix is 20 bits of the hash. In a database of 900 million passwords, a prefix matches roughly 900,000,000 / 16⁵ ≈ 880 hashes. Your password is indistinguishable from the other 879 in that bucket.

That's where the name comes from: k-anonymity, with k ≈ 880. The server knows somebody asked about that bucket. It does not know who, and it does not know which of the 880 you hold.

Why the prefix is safe even against a curious server

SHA-1 is broken for collision resistance, not for preimage resistance — nobody can reverse a hash to the password. But a server that receives the full hash could simply build a lookup table of common passwords, hashed, and match it. That's the actual risk, and it's why the suffix is withheld.

With only five characters, the server would need to enumerate every password whose hash starts with that prefix. It can — that's a 1/880 slice of the space — but the result is a list of hundreds of candidates, which is exactly what it already gave you. It learns nothing new.

What k-anonymity does not protect

Be precise about the threat model. K-anonymity protects your password from the checking service and from anyone watching that request in transit. It does not protect against:

  • A compromised browser. Malicious extensions can read the input before it is hashed. The check cannot save a password the page itself can read.
  • Timing and traffic analysis at scale. If a service logs which prefix each IP requested, and that IP later uses a site that leaks, correlation is possible. Rate limiting and not logging helps; a shared network makes it impractical.
  • The password already being weak. The database tells you about the past, not the future. A password that has never leaked can still be qwerty1234 from a site with no breach yet.

The same idea for the rest of the check

K-anonymity is also why the email check works differently. Email addresses cannot be k-anonymised the same way — the breach index is keyed by address, and a prefix of an address is close to the whole address. So Breachbeam's address checker sends the address over HTTPS to its own server, calls the Have I Been Pwned API, and returns the list of breaches without storing the address. Password checking and address checking are different problems and the tooling should not pretend otherwise.

What to look for in any checker

  • Does it make one request per password, containing only a prefix? (Five characters, /range/.)
  • Does it hash locally, in the browser?
  • Does it avoid sending the file, the list, or the plaintext anywhere?
  • Does it avoid writing results to localStorage or analytics?

You can watch all of it in the network tab. Breachbeam's scanner is built so that the only request it makes is the five-character prefix — and the source is public if you would rather read it than trust it.