-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassword_Health.py
190 lines (126 loc) · 4.76 KB
/
Password_Health.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
"""
User-Defined Functions
Coding Exercise: User-Defined Functions
Password Health
"""
#### ---- Setup ---- ####
Statement = {}
#### ---- Get Passwords ---- ####
def get_passwords(file="badpasswords.txt"):
### --- opening the file in read mode --- ###
my_file = open(file, "r")
### --- reading the file --- ###
data = my_file.read()
### --- replacing end splitting the text --- ###
### --- when newline ('\n') is seen. --- ###
data_into_list = data.split("\n")
return data_into_list
my_file.close()
#### ---- Password List ---- ####
def passwords_list(list):
user_passwords = list.split (",")
return user_passwords
#### ---- Simplified Password ---- ####
def simplified_password(passwords):
simplified_passwords = {}
for password in passwords:
original_password = password
password = password.lower()
### ---- END SYMBOL ---- ####
symbols = "!@#$%^&*.?"
if password[-1] in symbols:
password = password[:-1]
#### ---- END DIGITS ---- ####
for i in range(1, len(password)):
if password[i:].isdigit():
password = password[:i]
#### ---- SYMBOL REPLACEMENT ---- ####
symbol_map = {
"@": "a",
"3": "e",
"#": "h",
"1": "l",
"0": "o",
"$": "s",
"7": "t"
}
for symbol, replacement in list(symbol_map.items()):
password = password.replace(symbol, replacement)
simplified_passwords[original_password] = password
return simplified_passwords
def strong_password(passwords):
global Statement
Len = False
Cap = False
Low = False
Num = False
Spec = False
''' Checks whether the string s fits the
criteria for a valid password.
'''
capital = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
lowercase = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
number = ['0','1','2','3','4','5','6','7','8','9']
special = ['@','$','#','!','%']
for password in passwords:
for character in password:
if character in capital:
Cap = True
elif character in lowercase:
Low = True
elif character in number:
Num = True
elif character in special:
Spec = True
if len(password) >= 8:
Len = True
check = [Cap, Low, Num, Spec, Len]
Statement[password] = check
for key in Statement:
values = Statement[key]
count = values.count(True)
Statement[key] = count
#### ---- INPUT ---- ####
## -- Introduction -- ##
print("Check the health of your password by comparing it to common passwords.")
print("Then we will tell how strong your password is, if it is not similiar to a common password.")
print("You may enter multiple values with a comma. Please do not add spaces!")
## -- User input -- ##
user_input = input("What password would you like to check? ")
user_passwords = passwords_list(user_input)
for password in user_passwords:
if len(password) <= 3:
user_passwords.remove(password)
print("These are your current passwords: " + user_passwords)
user_input = input("Please enter a longer password then " + password + " to check: ")
user_passwords.append(user_input)
print("We will check these passwords: " + user_passwords)
print()
## -- Common passwords -- ##
bad_password = get_passwords()
## -- Variations -- ##
simplified_passwords = simplified_password(user_passwords)
strong_passwords = strong_password(user_passwords)
#### ---- OUTPUT ---- ####
## -- Base password -- ##
for password in user_passwords:
if password in bad_password:
Statement[password] = 0
print("Your password: " + password + " is too common.")
print()
## -- Variations -- ##
for key in simplified_passwords:
values = simplified_passwords[key]
if values in bad_password:
Statement[key] = 0
print("Your password: " + key + " is too similar to \"" + values + "\".")
print()
## -- Secure password -- ##
for key in Statement:
values = Statement[key]
if values <= 2:
print("Your password: " + key + " is not very secure!")
elif 4 >= values >= 3 :
print("Your password: " + key + " seems pretty secure!")
elif values == 5:
print("Your password: " + key + " is very secure!")