
Have I Been Pwned Has a Free API — Check If Any Email Was in a Data Breach
Why This Matters Data breaches happen daily. Have I Been Pwned (HIBP) tracks 14+ billion compromised accounts across 800+ breaches. Their API lets you check programmatically — no manual lookups. Check a Password (Without Sending It) HIBP uses a k-anonymity model. You send only the first 5 characters of the SHA-1 hash. The API returns all matching hashes. Your password never leaves your machine. import hashlib import requests def check_password ( password ): sha1 = hashlib . sha1 ( password . encode ()). hexdigest (). upper () prefix , suffix = sha1 [: 5 ], sha1 [ 5 :] r = requests . get ( f " https://api.pwnedpasswords.com/range/ { prefix } " ) for line in r . text . splitlines (): hash_suffix , count = line . split ( " : " ) if hash_suffix == suffix : return int ( count ) return 0 count = check_password ( " password123 " ) if count : print ( f " Found in { count : , } breaches! Change it immediately. " ) else : print ( " Not found in any known breach. " ) Output: Found in 126,927 brea
Continue reading on Dev.to Tutorial
Opens in a new tab


