Last active
March 12, 2019 19:36
-
-
Save unixfox/462315c633528784e864ce6cfe4f5141 to your computer and use it in GitHub Desktop.
Pwned checker based on the computerphile's video
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
#!/usr/bin/env python | |
import sys | |
import urllib.request | |
import hashlib | |
password = sys.argv[1] | |
passwordHashed = hashlib.sha1(password.encode('utf-8')).hexdigest().upper() | |
def fetchPwnedCount(passwordHashed): | |
passwordHashedKAnonymity = passwordHashed[:5] | |
requestPwnedPasswords = urllib.request.Request( | |
'https://api.pwnedpasswords.com/range/' + passwordHashedKAnonymity, | |
data=None, | |
headers={ | |
'User-Agent': 'Pwned checker based on the computerphile\'s video' | |
} | |
) | |
PwnedPasswordsMatchedHash = urllib.request.urlopen( | |
requestPwnedPasswords).read().decode('utf-8').split("\r\n") | |
for line in PwnedPasswordsMatchedHash: | |
if passwordHashed[5:] in line.split(":")[0]: | |
return(int(line.split(":")[1])) | |
return(0) | |
if (fetchPwnedCount(passwordHashed) > 1): | |
print(sys.argv[1] + ' was found') | |
print('Hash ' + passwordHashed + ', ' + str(fetchPwnedCount(passwordHashed)) + ' occurences') | |
elif (fetchPwnedCount(passwordHashed) == 1): | |
print(sys.argv[1] + ' was found') | |
print('Hash ' + passwordHashed + ', ' + str(fetchPwnedCount(passwordHashed)) + ' occurence') | |
elif (fetchPwnedCount(passwordHashed) == 0): | |
print(sys.argv[1] + ' was not found') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment