Compromised Password Detection
What You'll Learn
You'll learn how to protect users by checking their passwords against databases of leaked credentials, preventing them from reusing passwords that hackers already know.
Why Check Against Breach Databases?
Even if a user creates a password that meets all your complexity requirements, it might already be compromised. Data breaches happen constantly—when attackers steal passwords from other services, they compile massive databases of username/password combinations. Users who reuse passwords across sites become instant targets for credential stuffing attacks.
Compromised password detection acts like a security checkpoint at account creation or password reset: before accepting a new password, you verify it hasn't appeared in known breaches.
How It Works
The most popular service for this is Have I Been Pwned (HIBP), which maintains a database of billions of compromised passwords collected from public breaches.
The privacy-preserving approach:
- Hash the user's password locally (using SHA-1 for HIBP)
- Send only the first 5 characters of the hash to the API
- Receive back all breached password hashes starting with those 5 characters
- Check locally if the full hash matches any returned results
This "k-anonymity" model means the service never learns the actual password or even its complete hash—they only see a tiny prefix shared by thousands of passwords.
Think of it like this: Instead of asking "Is THIS exact book stolen?", you ask "Send me all stolen books starting with the letter 'H'", then check your book privately against that subset.
When a match is found, reject the password and explain to the user why—educating them about password reuse risks.
Key Takeaway:
Compromised password detection checks new passwords against breach databases like Have I Been Pwned using privacy-preserving techniques, preventing users from choosing credentials already known to attackers.