Created
February 12, 2021 14:37
-
-
Save fm-sys/7aab6f17a2c7a43adb38bc05c930197a to your computer and use it in GitHub Desktop.
A simple and secure password hash checker. Check if your chosen password is popular and has been exposed in security vulnerabilities without publishing the password itself. By using partial hashes the password doesn't leave your local pc at any time...
This file contains 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
import hashlib, requests, getpass | |
from threading import Event | |
passwort = getpass.getpass("Password: ") | |
sha_1 = hashlib.sha1(passwort.encode()) | |
pwHash = sha_1.hexdigest().upper() | |
print ("\nPassword hash:\t" + pwHash) | |
apiRequest = "https://api.pwnedpasswords.com/range/" + pwHash[:5] | |
print("API request:\t" + repr(apiRequest) + "\n") | |
r = requests.get(apiRequest) | |
if r.status_code != 200: raise Exception("API Request failed!") | |
for line in r.text.splitlines(): | |
if line.startswith(pwHash[5:]): | |
print("Password {:s} was leaked {:,} times. Don't use it!".format(repr(passwort), int(line.split(":")[1]))) | |
break | |
else: | |
print("The entered password isn't leaked, but this does not mean that it has to be 100% safe.") | |
Event().wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment