-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpurge.py
More file actions
85 lines (72 loc) · 3 KB
/
purge.py
File metadata and controls
85 lines (72 loc) · 3 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import time
import os
def is_reverse_consecutive(s):
return any(ord(s[i]) - 1 == ord(s[i + 1]) and ord(s[i + 1]) - 1 == ord(s[i + 2]) for i in range(len(s) - 2))
def is_consecutive(s):
return any(ord(s[i]) + 1 == ord(s[i + 1]) and ord(s[i + 1]) + 1 == ord(s[i + 2]) for i in range(len(s) - 2))
def contains_non_alphanumeric(s):
return any(not c.isalnum() for c in s)
def contains_uppercase(s):
return any(c.isupper() for c in s)
def contains_lowercase(s):
return any(c.islower() for c in s)
def contains_digit(s):
return any(c.isdigit() for c in s)
def contains_repeated_character(s):
return any(s[i] == s[i+1] == s[i+2] for i in range(len(s) - 2))
def valid_password(password):
if len(password) < 8:
return "too short"
if len(password) > 72: # BCRYPT max length 72
return "too long"
if not contains_uppercase(password):
return "must contain uppercase"
if not contains_lowercase(password):
return "must contain lowercase"
if not contains_digit(password):
return "must contain digit"
if not contains_non_alphanumeric(password):
return "must contain non alphanumeric"
if contains_repeated_character(password):
return "no repeated charakters e.g. aaa, 111"
if is_consecutive(password):
return "no consecutive chars e.g. abc, 123"
if is_reverse_consecutive(password):
return "no reverse consecutive chars e.g. cba, 321"
return "valid password"
def main():
with open("8-plus.txt", "w") as target:
for filename in os.listdir("src"):
if filename.endswith(".txt"):
source_file = os.path.join("src", filename)
with open(source_file, "r") as source:
for password in source:
password = password.rstrip("\n")
if valid_password(password) == "valid password":
target.write(password + "\n")
def makePHP():
with open("8-plus.txt", "r") as source_file:
with open("8-plus.php", "w") as target_file:
target_file.write("<?php\n")
target_file.write("$passwords = array(\n")
for password in source_file:
password = password.replace("'", "\\'")
password = password.rstrip("\n")
target_file.write("'" + password + "',\n")
target_file.write(");\n")
# target_file.write("?>\n")
def makeSQL():
with open("8-plus.txt", "r") as source_file:
with open("8-plus.sql", "w") as target_file:
target_file.write("INSERT INTO `passwords` (`password`) VALUES\n")
for password in source_file:
password = password.replace("'", "''")
password = password.rstrip("\n")
target_file.write("('" + password + "'),\n")
target_file.write(";\n")
if __name__ == '__main__':
start_time = time.time()
main()
makePHP()
makeSQL()
print("--- %s seconds ---" % (time.time() - start_time))