Merge pull request #10 from d-chris/master

changed password encoding to utf-8 for sha-1
This commit is contained in:
Michael Pound 2019-03-14 12:30:28 +00:00 committed by GitHub
commit af78272fdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,12 @@
import hashlib import hashlib
import requests
import sys import sys
try:
import requests
except ModuleNotFoundError:
print("### pip install requests ###")
raise
def lookup_pwned_api(pwd): def lookup_pwned_api(pwd):
"""Returns hash and number of times password was seen in pwned database. """Returns hash and number of times password was seen in pwned database.
@ -18,7 +23,7 @@ def lookup_pwned_api(pwd):
RuntimeError: if there was an error trying to fetch data from pwned RuntimeError: if there was an error trying to fetch data from pwned
database. database.
""" """
sha1pwd = hashlib.sha1(pwd.encode('ascii')).hexdigest().upper() sha1pwd = hashlib.sha1(pwd.encode('utf-8')).hexdigest().upper()
head, tail = sha1pwd[:5], sha1pwd[5:] head, tail = sha1pwd[:5], sha1pwd[5:]
url = 'https://api.pwnedpasswords.com/range/' + head url = 'https://api.pwnedpasswords.com/range/' + head
res = requests.get(url) res = requests.get(url)