Skip to content
← Back to blog
4 min Herramientas y proyectos en

Check if a password leaked without sending it to anyone

Have I Been Pwned lets you check a password against 800M+ leaked ones without revealing it, thanks to k-anonymity. How I built it into Password Sentinel.

Written by Eduardo Olivares, SOC analyst in Barcelona.

  • cryptography
  • have-i-been-pwned
  • k-anonymity
  • extensions
  • javascript
  • privacy

Short answer: yes, you can check a password without revealing it. You compute the SHA-1 of the password locally, send only the first five characters of the hash to Have I Been Pwned, and do the final comparison in the browser. The server never sees your password or the full hash. The technique is called k-anonymity.

When I built Password Sentinel, a browser extension that warns you if a password appears in known breaches, the problem wasn't technical. It was trust. To know whether your password is in a breach you have to compare it against a corpus of hundreds of millions of entries, and that corpus doesn't fit inside an extension.

The obvious solution is to ask a server. The obvious solution is also terrible: my extension would be sending your passwords to a third party. Nobody should install that, and I didn't want to write it.

The trick: ask without saying what you're asking

Have I Been Pwned solves this with a technique called k-anonymity. Instead of asking about your password, you ask about a group of candidates large enough for yours to get lost inside it.

The procedure has three steps:

  • Compute the SHA-1 of the password locally, inside the browser.
  • Send the server only the first five hexadecimal characters of that hash. Nothing else.
  • The server returns every hash in its database that starts with that prefix, and the final comparison happens locally again.
Password:    correcthorsebatterystaple
SHA-1:       BE4A8DE9AFCEE30B29C0A0AB29F9E7A9CF4E1B2C
Sent:        BE4A8
Received:    ~800 suffixes starting with BE4A8
Compared:    in the browser, against the list received

Why the numbers work

Five hexadecimal characters give 16^5, a little over a million possible prefixes. Spread over a corpus of about 850 million hashes, each prefix gets on the order of 800 candidates.

That means the server knows you asked about one of roughly 800 passwords, with no way to tell which. It can't narrow it down with repeated requests either, because every query returns the whole group: there is no second attempt that tightens the circle.

Three details worth keeping in mind

SHA-1 isn't a flaw here. It's the first thing that jumps out when you read the protocol, and the answer is that SHA-1 isn't being used as a security function: it's the index into the corpus. SHA-1 collisions don't help anyone work out what you asked, because the sensitive part never leaves the browser. Using SHA-1 to store passwords would be a different matter, and a serious mistake.

TLS is still needed. K-anonymity protects you from the server. It doesn't protect you from someone watching the network who can see the prefix. They are two separate layers and you need both.

Zero matches doesn't mean a good password. This is the most common misunderstanding. A password missing from the corpus only means it hasn't leaked yet. Barcelona2026! will probably return zero results and is still a terrible password: it falls to any dictionary attack with rules. A breach check rules out what is already known to be broken; it doesn't certify what's left.

What I took away from writing it

I care less about the cryptography in k-anonymity than about the framing. The starting question wasn't how do I encrypt this, it was what is the minimum the other side needs to know to answer me. Almost always it's much less than what ends up being sent out of habit.

It's the same reasoning I apply to this site's analytics: I don't store IP addresses because I don't need them to count visitors. I store a salted hash and that's enough. Collecting data you don't need isn't neutral: it's taking on risk for nothing.

Frequently asked questions

Is it safe to check my password on Have I Been Pwned?

With the range method, yes. Your password and its full hash never leave the browser: only the first five characters of the hash travel, which match about 800 different candidates. The connection uses TLS, so someone watching the network doesn't see it either.

Why use SHA-1 if it's broken?

Because it protects nothing here: it only serves as an index to find the group of hashes. SHA-1 collisions don't help anyone work out which password you searched for. Using it to store passwords would be a serious mistake.

If my password isn't in any breach, is it a good one?

Not necessarily. It only means it hasn't leaked yet. A predictable password like Barcelona2026! can return zero results and still fall to a dictionary attack with rules.