Created
February 24, 2018 15:25
-
-
Save rectalogic/613ca5192f35eb2103d1aacd16619709 to your computer and use it in GitHub Desktop.
Simple python pwned password checker for https://haveibeenpwned.com/API/v2#PwnedPasswords
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import getpass | |
import hashlib | |
import urllib2 | |
def check_password(password): | |
sha = hashlib.sha1(password).hexdigest().upper() | |
sha_prefix = sha[:5] | |
sha_suffix = sha[5:] | |
request = urllib2.Request("https://api.pwnedpasswords.com/range/" + sha_prefix, headers={"User-Agent": "pwned.py"}) | |
response = urllib2.build_opener().open(request).read() | |
hashcounts = [line.split(":") for line in response.splitlines()] | |
matchcount = next((c for h, c in hashcounts if h == sha_suffix), None) | |
if matchcount: | |
print("Found %s matches" % (matchcount,)) | |
else: | |
print("No matches found") | |
if __name__ == '__main__': | |
check_password(getpass.getpass()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment