-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (37 loc) · 1.37 KB
/
main.py
File metadata and controls
62 lines (37 loc) · 1.37 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
49
50
51
52
53
54
55
56
57
import requests
import hashlib
import sys # noqa: F401
from postq import call
def request_bytes(query:str):
url: str ="https://api.pwnedpasswords.com/range/" + query
res = requests.get(url)
if res.status_code!=200:
raise RuntimeError(f"an error {res.status_code} has occured")
return res
def get_count(hashes,rest):
hashes = (line.split(':') for line in hashes.text.splitlines())
for _,count in hashes:
if (_ == rest) :
return count
return 0
def check_api(password) -> str:
passwd = hashlib.sha1(password.encode('utf-8')).hexdigest().upper()
kanom,rest = passwd[:5],passwd[5:]
response= request_bytes(kanom)
return get_count(response,rest)
def main(args):
for _ in args:
l=len(_)
cc=check_api(_)
if cc:
print(f"YOUR PASS : {_} HAS BEEN BREACHED {cc} TIMES !")
print(f"YOU MUST UPDATE {_} WITH ONE OF THE FOLLOWING :")
call(l)
print("the longer the pass you set , the better")
else:
print(f"good News ! your pass {_} is safe for now ")
print(f"you may consider updating : {_} with one of the post quantum passwords for maximum safety")
call(l)
print("the longer the pass you set , the better")
if __name__ == '__main__':
sys.exit(main(sys.argv[1:])) #wiwi sleep()