-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
325 lines (287 loc) · 15.4 KB
/
run.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/usr/bin/env python3.6
import pyperclip
from user import User
from credentials import Credentials
def create_user(fname, uname, password):
'''
This is a function to create a new user
'''
new_user = User(fname , uname, password)
return new_user
def save_user(user):
'''
This function saves a new user
'''
user.save_user()
def del_user(user):
'''
This function deletes a user
'''
user.delete_user()
def create_new_credential(user_account, account_password):
'''
This function allows a user create a new credential account
'''
new_credential = Credentials(user_account , account_password)
return new_credential
def save_new_credentials(credential):
'''
This is a function to save new credentials created
'''
credential.save_credential()
def delete_credentials(credential):
'''
This is a function to delete credentials by the user
'''
return Credentials.delete_credential(credential)
def verify_user(name):
'''
Function that checks if the username already exists in the system
'''
checking_user = Credentials.find_by_name(name)
return checking_user
def find_credentials(user_account):
'''
Function to find stored credentials
'''
return Credentials.find_by_name(user_account)
def check_existing_credentials(name):
'''
Function to check if an inputed credential name exists
'''
return Credentials.find_by_name(name)
def copy_credential(user_account):
'''
Function to copy a credentials details to the clipboard
'''
return Credentials.copy_credential(user_account)
def display_credential():
'''
Function to display credentials of an account
'''
return Credentials.display_credential()
def generate_password():
'''
This is a function to generate random password
'''
gen_pass = Credentials.generate_password()
return gen_pass
def main():
print("")
print("")
print(" WELCOME TO THE .....|| ")
print(" || ")
print(" || ")
print(" vv ")
print("' /$$ /$$ /$$ /$$")
print("' | $$ | $$ | $$ | $$")
print("' /$$$$$$ /$$$$$$ /$$$$$$$/$$$$$$$/$$ /$$ /$$ /$$$$$$ /$$$$$$ /$$$$$$$ | $$ /$$$$$$ /$$$$$$| $$ /$$ /$$$$$$ /$$$$$$| $$")
print("' /$$__ $$|____ $$/$$_____/$$_____| $$ | $$ | $$/$$__ $$/$$__ $$/$$__ $$ | $$ /$$__ $$/$$_____| $$ /$$//$$__ $$/$$__ $| $$")
print("' | $$ \ $$ /$$$$$$| $$$$$| $$$$$$| $$ | $$ | $| $$ \ $| $$ \__| $$ | $$ | $$ | $$ \ $| $$ | $$$$$$/| $$$$$$$| $$ \__|__/")
print("' | $$ | $$/$$__ $$\____ $\____ $| $$ | $$ | $| $$ | $| $$ | $$ | $$ | $$ | $$ | $| $$ | $$_ $$| $$_____| $$ ")
print("' | $$$$$$$| $$$$$$$/$$$$$$$/$$$$$$$| $$$$$/$$$$| $$$$$$| $$ | $$$$$$$ | $$$$$$$| $$$$$$| $$$$$$| $$ \ $| $$$$$$| $$ /$$")
print("' | $$____/ \_______|_______|_______/ \_____/\___/ \______/|__/ \_______/ |________/\______/ \_______|__/ \__/\_______|__/ |__/")
print("' | $$ ")
print("' | $$ ")
print("' |__/ ")
print(" ")
print(" please what is your name?")
first_name = input()
print(f" Hello {first_name} what would you like to do today?")
print (" ")
while True:
print("Please use the following short codes :\n cc - to create new account ,\n li - Log in ,\n ex - to exit password locker")
short_code = input().lower()
if short_code == "cc":
print ("-"*15)
print (" ")
print ("To create a new user account: ")
first_name = input(" Please enter your first name:- ")
user_name = input("Please enter your preferred username :- ")
password = str(input (" Please enter your desired password:- "))
confirm_password = str(input ("Please confirm your password:- "))
save_user(create_user(first_name,user_name,password))
print("")
print(f" New account has been created for : {first_name} \n with username :{user_name} \n using password: {password}")
print("")
while confirm_password != password :
print("sorry your passwords do not match")
print("Enter your password again")
password = str(input (" Please enter your desired password:- "))
confirm_password = str(input ("Please confirm your password:- "))
else:
print(f" Congratulations {user_name}! You have created your account.")
print(" ")
print(" Now login to to your credential Account")
new_user_name = input("please enter your username :- ")
new_password = str(input ("Please enter your password:- "))
save_user(create_user(first_name,user_name,password))
print("")
print(f"New account has been created for : {first_name} \n with username :{user_name} \n using password: {password}")
while new_user_name != user_name or new_password != password:
print("you have entered a wrong username and password")
print("Please enter your logon information again....")
new_user_name = input("Please enter your username :- ")
new_password = str(input ("Please enter your password:- "))
else:
print(f"Welcome {new_user_name} to your Credential Account")
print(" ")
while True:
print("Select an option below to continue:")
print("")
print("a: View your saved accounts")
print("b: Add a new account")
print("c: Delete credentials")
print("d: Find an account")
print("e: logout")
print("copy: copy information")
option = input()
if option == 'e':
print("bye....")
break
elif option == "c":
while True:
print("Type credential name you want to delete......")
search_account = input()
if check_existing_credentials(search_account):
search_credential = find_credentials(search_account)
print(f"Account :{search_credential.user_account}\n Password: {search_credential.account_password}")
print(f"are you sure you want to delete {search_credential.user_account} ? y or n")
answer = input().lower()
if answer == 'y':
delete_credentials(search_credential)
print("Account has been deleted sucessfully")
break
elif answer == 'n':
continue
else:
break
elif option == "b":
while True:
print("do you want to add an account y OR n")
choice = input().lower()
if choice == "y":
print ("Enter Account Name")
user_account = input()
print("Enter your desired password")
print("To use your own password use 'p' or Generate a random one use 'g' ")
keyword = input().lower()
if keyword == "p" :
print("Create your own password : ")
account_password = input()
print(f" Account : {user_account}")
print(f" Password : {account_password}")
print(" ")
elif keyword == "g":
account_password = generate_password()
print(f" Account : {user_account}")
print(f" Password : {account_password}")
print(" ")
else:
print("please create a password")
save_new_credentials(create_new_credential(user_account,account_password))
elif choice == "n":
print("Bye .....")
break
elif option == "a":
print("")
if display_credential():
for credential in display_credential():
print(f"Account Name : {credential.user_account}")
print(f"Password : {credential.account_password}")
else:
print("")
print(" You don't have any credentials yet")
print("")
elif option == "d":
while True:
print("Enter an account name to find credentials")
search_account = input()
if check_existing_credentials(search_account):
search_account = find_credentials(search_account)
print(f"{search_account.user_account} \n {search_account.account_password}")
print('-'*10)
else:
print("The credential doesn't exist")
break
elif option == "copy":
print("")
this_account = input("Enter Account name for password to copy: ")
copy_credential(this_account)
print("")
elif short_code == "li":
print("WELCOME")
print("-"*60)
print(" To login , enter your account deails : ")
user_name = input("Enter your usename name :- ")
password = str(input("Enter your password :- "))
user_exists = verify_user(user_name)
if user_exists == user_name :
print(" ")
print (f"Welcome back {user_name} . /n Please choose an option to continue")
print(" ")
while True:
print("Select an option below to continue:")
print("")
print("a: View your save accounts")
print("b: Add a new account")
print("c: Delete credentials")
print("d: Find an account")
print("e: logout")
option = input()
if option == 'e':
print("bye....")
break
elif option == "b":
while True:
print("do you want to add an account y OR n")
choice = input().lower()
if choice == "y":
print ("Enter Account Name")
user_account = input()
print("Enter your desired password")
print("To use your own password use 'p' or Generate a random one use 'g' ")
keyword = input().lower()
if keyword == "p" :
print("Create your own password : ")
account_password = input()
print(f" Account : {user_account}")
print(f" Password : {account_password}")
print(" ")
elif keyword == "g":
account_password = generate_password()
print(f" Account : {user_account}")
print(f" Password : {account_password}")
print(" ")
else:
print("please create a password")
save_new_credentials(create_new_credential(user_account,account_password))
elif choice == "n":
print("Bye .....")
break
elif option == "a":
print("")
if display_credential():
for credential in display_credential():
print(f"Account Name : {credential.user_account}")
print(f"Password : {credential.account_password}")
else:
print("")
print(" You don't have any credentials yet")
print("")
elif option == "d":
while True:
print("Enter an account name to find credentials")
search_account = input()
if check_existing_credentials(search_account):
search_account = find_credentials(search_account)
print(f"{search_account.user_account} \n {search_account.account_password}")
print('-'*10)
else:
print("The credential doesn't exist")
break
elif short_code == "ex":
print("Bye....we hope you again visit soon")
break
if __name__ == '__main__':
main()