DEV Community

Cover image for How a leaked password check works without sending the full password
System Design Simple
System Design Simple

Posted on Originally published at systemdesignsimple.com

How a leaked password check works without sending the full password

You can check whether a password appears in a known breach corpus without sending the full password to the lookup service. The Pwned Passwords range API receives only the first 5 characters of the password's SHA-1 hash and returns every breached hash in that bucket, so the final comparison happens on your side.

How the range API works

SHA-1 turns a password into 40 hex characters. The first 5 select one of 16^5 = 1,048,576 buckets. Every bucket exists, so a range query answers 200 rather than 404, and each line of the reply is a 35 character suffix, a colon and a count.

A worked example: password123 hashes to CBFDAC6008F9CAB4083784CBD1874F76618D2A97. Your code sends GET /range/CBFDA and scans the reply for the remaining suffix. The line it finds carries the count. The range API is free and needs no key.

What our lab showed

We ran a check on our Mac on 2026-11-06 with four test passwords: two famous weak ones, one that passes the usual complexity rules, and a random 20 character password.

Password Prefix sent Times seen
password123 CBFDA 2,266,543
letmein B7A87 1,406,604
Summer2024! 7E8B0 3,614
random 20 chars 6C4CB 0

Summer2024! satisfies the usual complexity regex, one capital, one digit, one symbol, and was still seen 3,614 times. Only the random password was absent. Composition rules push people toward the same patterns, and breached passwords satisfy them.

What the 5 character prefix still reveals

The request reveals 20 of 160 bits. That narrows guesses, most of all for common passwords: if the bucket holds a suffix seen two million times, anyone who learns the prefix has a strong first guess. The Add-Padding: true header adds count-0 rows to obscure the response size signal, which reduces it rather than removing it.

Two habits in your own code matter more: check once, on submit, and never log the prefix next to a user id.

The sign-up policy that follows

NIST SP 800-63B-4 asks for at least 15 characters when a password is the only factor, 8 when it is part of multi-factor login, no composition rules, and a blocklist check when a password is set or changed. Apply NFC normalization before hashing, and check the result against the blocklist.

The code should fail closed: a timeout, a non-200 status or a malformed body all end in a retry message, never in accepting the password. Skipping the check when the API fails is the one option to avoid.

And SHA-1 is only the lookup key here, never the storage: store passwords with Argon2id, or scrypt as the fallback. Add this check at sign-up and password change. It costs one request on submit and rejects breached passwords that composition rules let through.

Read the full article with the code, the lab table and the fix checklist: https://systemdesignsimple.com/is-my-password-leaked-how-the-check-works/

Top comments (0)