-
Notifications
You must be signed in to change notification settings - Fork 1
/
password_manager.py
129 lines (108 loc) · 4.02 KB
/
password_manager.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
# password_manager.py
# make and show passwords
# Brian =^._.^=
import re
logins = {}
with open("logins.txt", "r") as f:
lines = f.readlines()
for line in lines:
f_username = line[line.index("|") + 1:line.index(";")]
f_password = line[line.index(";") + 1:-1]
f_app = line[:line.index("|")]
info = [f_password, f_app]
logins[f_username] = info
print(logins)
print("Hello World")
print("test1234123")
print("Wilco is for sure cool.")
class PasswordManager():
def __init__(self):
print("Hello and welcome to pwManage")
self.run()
def run(self):
self.age_check()
running = True
while running:
option = self.integer_check("What would you like to do? "
"(Enter Number) \n"
" 1. Add a new login \n"
" 2. View Logins \n"
" 3. Exit application \n")
if option == 1:
self.create_login()
elif option == 2:
self.check_logins()
elif option == 3:
self.cya_lol()
else:
print("Please enter a valid option")
def cya_lol(self):
print("goodbye mens))")
exit()
def integer_check(self, question):
while True:
try:
num = int(input(question))
if num <= 0:
print("Please input a positive number.")
continue
return num
except ValueError:
print("Please input a valid number.")
def age_check(self):
age = self.integer_check("How old are you? ")
if age < 13:
print("You are not old enough to use this application.")
self.cya_lol()
elif age > 140:
print("There is no way you are this old.")
self.cya_lol()
def password_check(self, pw):
password_regex = re.compile(r"""
(?=.*[A-Z]) # must match atleast 1 Upper
(?=.*[a-z]) # must match atleast 1 Lower
(?=.*\d) # must match atleast 1 Digit
.{8,} # must match 8 of the above
""", re.VERBOSE)
if password_regex.search(pw) is None:
return False
else:
return True
def create_login(self):
create_name = True
create_pass = True
while create_name:
application = input("What app is the login going to be for? ")
username = input("What would you like your username to be? ")
if username in logins:
print("Username %s already exists." % (username))
continue
create_name = False
while create_pass:
password = input("Please input the password for the username "
"(Password must include at least 1 uppercase, "
"1 lowercase and 1 number): ")
eligible = self.password_check(password)
if not eligible:
print("Your password does not meet the requirements. "
"Please try again: \n")
continue
create_pass = False
info = [password, application]
logins[username] = info
with open("logins.txt", "a") as f:
f.write("%s|%s;%s\n" % (application, username, password))
print("Username and password added to logins. \n")
def check_logins(self):
if not logins:
print("There are no logins.")
else:
print()
for count, i in enumerate(logins):
print("%s. App: %s, Username: %s, Password: %s"
% (count + 1, logins[i][1], i, logins[i][0]))
print("")
def main():
PasswordManager()
if __name__ == '__main__':
main()