Skip to content

Instantly share code, notes, and snippets.

@unixfox
Last active March 12, 2019 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unixfox/462315c633528784e864ce6cfe4f5141 to your computer and use it in GitHub Desktop.
Save unixfox/462315c633528784e864ce6cfe4f5141 to your computer and use it in GitHub Desktop.
Pwned checker based on the computerphile's video
#!/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