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
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.