Passwords which have previously been exposed in data breaches
Checks if passwords have been exposed in data breaches using the k-Anonymity model.
import hashlib
import requests
# To check a password, compute its SHA-1 hash and take the first 5 characters.
password = "your_secret_password"
sha1_hash = hashlib.sha1(password.encode('utf-8')).hexdigest().upper()
prefix = sha1_hash[:5]
url = f"https://api.pwnedpasswords.com/range/{prefix}"
response = requests.get(url)
# The response contains SHA-1 suffixes and counts of breaches.
# You then compare the full SHA-1 hash suffix against these.
print(response.text)Last 50 checks (10 min intervals)