-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpass_lib.py
50 lines (40 loc) · 1.7 KB
/
pass_lib.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
48
49
50
import requests
import hashlib
def passme_password(password, engine="HIBP", api_key="0"):
encoded_password = hashlib.sha1(str.encode(password)).hexdigest()
return(passme_hash(encoded_password, engine, api_key))
def passme_hash(hashed_password, engine="HIBP", api_key="0"):
if engine == "HIBP":
return(engine_HIBP(hashed_password, engine, api_key))
elif engine == "BD":
print("DataBreach")
else:
print("Engine not implemented, defaulting to HIBP.")
passme_hash(hashed_password, engine="HIBP", api_key=api_key)
def passme_file(filename, engine="HIBP", api_key="0"):
with open(filename) as file_in:
for line in file_in:
line = line.rstrip("\n")
print("Password: " + line)
passme_password(line, engine, api_key)
print("")
def passme_list(filename, engine="HIBP", api_key="0"):
with open(filename) as file_in:
for line in file_in:
passme_hash(line, engine, api_key)
print("Hash: " + line)
def engine_HIBP(hashed_password, engine, api_key):
word_count = len(hashed_password)
if word_count >= 5:
hashed = hashed_password[5:35].upper()
response = requests.get("https://api.pwnedpasswords.com/range/"
+ hashed_password[0:5],
headers={'Add-Padding': 'true', 'hibp-api-key': api_key})
if hashed in response.text:
print("It is possible that your password has been filtered.")
return("F")
else:
print("Your password has not been filtered yet.")
return("N")
else:
print("Invalid Hash, please use a prefix of at least 5 characters.")