-
Notifications
You must be signed in to change notification settings - Fork 0
/
passcheck.py
47 lines (35 loc) · 1.25 KB
/
passcheck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import requests
import hashlib
def request_api(query_char):
url = 'https://api.pwnedpasswords.com/range/' + query_char
res = requests.get(url)
if res.status_code != 200:
raise RuntimeError(f'Error Fetching: {res.status_code}, Try API AGAIN!!')
return res
def get_leaked(hashes, hash_to_check):
hashes = (line.split(':') for line in hashes.text.splitlines())
for h, count in hashes:
if h == hash_to_check:
return count
return 0
def pwned_pass(passwords):
sha1pass = hashlib.sha1(passwords.encode('utf-8')).hexdigest().upper()
first5_char, rest = sha1pass[:5], sha1pass[5:]
response = request_api(first5_char)
return get_leaked(response, rest)
def main(args):
count = pwned_pass(args)
if count:
print(f'''
Password {args} has been Hacked {count} times...
Try a more secure Password!!
''')
else:
print(f'''
HOORAY!!! Password {args} Has not been Breached or hacked
You can continue with this password!!
''')
return 'Check Complete!!!'
if __name__ == '__main__':
inp = input('Type in the password you want to check: ')
exit(main(inp))