-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_checker.py
More file actions
49 lines (33 loc) · 1.23 KB
/
Copy pathpassword_checker.py
File metadata and controls
49 lines (33 loc) · 1.23 KB
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
48
import sys
import hashlib
import requests
PASSWORD_FILE = r"C:\Users\harsh\OneDrive\Desktop\harshit.txt"
def request_api_data(first5):
url = f"https://api.pwnedpasswords.com/range/{first5}"
res = requests.get(url)
if res.status_code != 200:
raise RuntimeError(f"API error: {res.status_code}")
return res
def password_leaks_count(hashes, hash_to_check):
for h, count in (line.split(':') for line in hashes.text.splitlines()):
if h == hash_to_check:
return int(count)
return 0
def pwned_api_check(password):
sha1password = hashlib.sha1(password.encode("utf-8")).hexdigest().upper()
first5, tail = sha1password[:5], sha1password[5:]
response = request_api_data(first5)
return password_leaks_count(response, tail)
def main():
with open(PASSWORD_FILE, "r", encoding="utf-8") as f:
passwords = [line.strip() for line in f if line.strip()]
print("Passwords loaded:", passwords) # Debug line
for pw in passwords:
count = pwned_api_check(pw)
if count:
print(f"{pw} was found {count} times. Choose another password.")
else:
print(f"{pw} not found. Good to go!")
return "done"
if __name__ == "__main__":
(main())