Menu

Building a Zero-Knowledge Password Exposure Checker in Vanilla JS Using the Web Crypto API
📰

Building a Zero-Knowledge Password Exposure Checker in Vanilla JS Using the Web Crypto API

DEV Community: cybersecurity·anass hanafi·10 days ago
#E0gPmpmY
#devtocybersecurity#devto#dev#const#password
Long article (453 words) — no AI summary yet.
Reading 0:00
15s threshold

When users want to check whether a password has been leaked in a data breach, pasting it into a standard form that sends the plaintext string to a backend server is a major security anti-pattern.

Fortunately, you can build a zero-knowledge password audit tool directly in the browser using the native Web Crypto API ( crypto.subtle ) and the k-Anonymity range model —with zero external dependencies.

How the k-Anonymity Range Model Works

Instead of transmitting a password or even its full hash over the network, the client only shares a 5-character hash prefix:

Hash Locally: Compute the SHA-1 digest of the password inside the browser.

Split the Digest: Take the first 5 hex characters ( prefix ) and keep the remaining 35 characters ( suffix ) in local memory.

Query the Range API: Send only the 5-character prefix to https://api.pwnedpasswords.com/range/{prefix} .

Compare Locally: The API returns hundreds of matching hash suffixes alongside breach counts.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.