changed password encoding to utf-8 for sha-1

according to api
https://haveibeenpwned.com/API/v2#PwnedPasswords
This commit is contained in:
d-chris 2019-03-14 11:50:17 +01:00 committed by GitHub
parent 521c441a6a
commit 112748240d
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)