changed password encoding to utf-8 for sha-1
according to api https://haveibeenpwned.com/API/v2#PwnedPasswords
This commit is contained in:
parent
521c441a6a
commit
112748240d
9
pwned.py
9
pwned.py
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user