Skip to main content
KavachOS integrates with the HaveIBeenPwned Pwned Passwords API to detect compromised passwords at sign-up and password change. It uses the k-anonymity model, only the first 5 characters of the SHA-1 hash are sent to the API. Your users’ actual passwords never leave your server.

Setup

lib/kavach.ts

check() and enforce()

The module exposes two methods with different failure modes:
Manual usage
check() is useful when you want to warn the user without blocking them. enforce() integrates directly into the password validation lifecycle and blocks the request.

How k-anonymity works

The full password hash is never transmitted. The API response contains partial hashes from other users’ passwords, so the provider cannot determine which password you were checking.

Custom API key

The HIBP Passwords API is free and does not require authentication, but a paid key removes rate limits:
lib/kavach.ts
If the HIBP API is unreachable, check() returns { breached: false } and enforce() passes through. The default behavior is fail-open so a slow network does not block your users from registering. Set failClosed: true to change this.

Configuration reference

string
Optional HIBP API key for higher rate limits.
number
default:"3000"
Milliseconds to wait for the HIBP API before giving up.
boolean
default:"false"
Reject the password if HIBP is unreachable instead of passing through.
number
default:"1"
Minimum breach count before a password is considered compromised.
Last modified on April 20, 2026