ShieldX Toolly
Open a tool Donate
Home Home
Blog Blog
FAQ FAQ
Open a tool Donate
Back to cheatsheets
Privacy

Breach Checking (k-Anonymity)

Check passwords against breach databases without leaking them using the k-anonymity protocol.

2 snippets Intermediate breach-checker
k-anonymitySHA-1Have I Been Pwnedbreach

What you'll learn

  • SHA-1 hash + k-anonymity
  • Batch breach check

How to use these snippets

  1. Click the Copy button next to any snippet to copy it to your clipboard.
  2. Paste the code into your project, IDE, or terminal.
  3. Replace placeholder values (like example.com or your-secret) with your actual data.
  4. Review the code comments for important security notes and caveats.
  5. Try the interactive related tool to see the concept in action.
Code Snippets

Copy-paste code snippets

2 ready-to-use snippets for breach checking (k-anonymity). Click copy and paste into your project.

SHA-1 hash + k-anonymity
                async function checkBreach(password) {
  const data = new TextEncoder().encode(password);
  const buf = await crypto.subtle.digest('SHA-1', data);
  const hash = Array.from(new Uint8Array(buf))
    .map(b => b.toString(16).padStart(2, '0'))
    .join('').toUpperCase();
  const prefix = hash.slice(0, 5);
  const suffix = hash.slice(5);
  const res = await fetch(
    `https://api.pwnedpasswords.com/range/${prefix}`
  );
  const text = await res.text();
  const match = text.split('\n')
    .find(l => l.split(':')[0] === suffix);
  return match ? parseInt(match.split(':')[1]) : 0;
}
              
Batch breach check
                async function batchCheck(passwords) {
  const results = [];
  for (const pw of passwords) {
    const count = await checkBreach(pw);
    results.push({ password: '***', breachCount: count });
  }
  return results.sort((a, b) => b.breachCount - a.breachCount);
}
              
Tool

Try this concept hands-on with the interactive tool.

100% Free · No signup · No cost

Generate something unguessable right now

148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.

Open the toolkit

Part of the Toolly ecosystem · secure.toolly.site