Created
January 22, 2019 22:24
-
-
Save wowkin2/2d66c67baa7c1b7d0697aa4d31abacb2 to your computer and use it in GitHub Desktop.
API to check password on HaveIBeenPwned service
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 | |
import requests | |
import getpass | |
def test_pw(byte_string): | |
hasher = hashlib.sha1() | |
hasher.update(byte_string) | |
digest = hasher.hexdigest().upper() | |
print(f'Hash: {digest[:5]}, {digest[5:]}') | |
print(f'GET https://api.pwnedpasswords.com/range/{digest[:5]}') | |
pw_list = requests.get(f'https://api.pwnedpasswords.com/range/{digest[:5]}') | |
for line in pw_list.text.split('\n'): | |
info = line.split(':') | |
if info[0] == digest[5:]: | |
print(f'Pwned! Seen {int(info[1])} times.') | |
break | |
else: | |
print('Not found') | |
pw = getpass.getpass() | |
test_pw(pw.encode()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment