-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·405 lines (344 loc) · 20 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#!/usr/bin/env python3
from users import Users
from credentials import Credentials
def create_user(username, login_password):
'''
Function to create new user
'''
new_user = Users(username, login_password)
return new_user
def add_user(user):
'''
Function to save user
'''
user.add_user()
def remove_user(user):
'''
Function to delete user
'''
user.delete_user()
def find_user(username):
'''
Function to find user by username
'''
return Users.find_by_username(username)
def check_existing_user(username, login_password):
'''
Function to authenticate user
'''
return Users.user_exists(username, login_password)
def create_credentials(application_name, account_username, account_password):
'''
Function to create new credentials
'''
new_credentials = Credentials(
application_name, account_username, account_password)
return new_credentials
def add_credentials(new_credentials):
'''
Function to save credentials
'''
new_credentials.add_credentials()
def remove_credentials(new_credentials):
'''
Function to delete credentials
'''
new_credentials.delete_credentials()
def display_credentials():
'''
Function that returns all saved credentials
'''
return Credentials.display_credentials()
def check_existing_credentials(application_name):
'''
Function to check that credentials for a certain application exist
'''
return Credentials.credentials_exist(application_name)
def find_credentials(application_name):
'''
Function that finds credentials using the application name
'''
return Credentials.find_by_application_name(application_name)
def generate_a_password(passwordLength):
'''
Function that generates random password of 8 characters
'''
return Credentials.generate_password(passwordLength)
def main():
print(" "*8 + "✧ 🎀 𝓅𝒶𝓈𝓈𝓌🍪𝓇𝒹 𝓁🌸𝒸𝓀𝑒𝓇 🎀 ✧" + " "*8)
print("--"*24)
print("An application that manages your passwords.")
while True:
print("What is your name?")
current_user = input().strip(' ').capitalize()
if current_user != '':
print(f"\nHello👋 {current_user},")
while True:
print("Kindly use these short codes to navigate the application🤗 : \n CA - create an account \n SI - sign into an existing account \n DA - delete your account \n EX - exit the application ")
short_code = input().upper()
if short_code == 'CA':
print("\nCREATE AN ACCOUNT")
print("-"*17)
print("Enter a name you wish to use as your username")
print(
" "*4 + "*the username must contain alphabetical letters only and no spaces*")
while True:
username = input().capitalize()
if username.isalpha():
print("Enter a password for your account")
print(
" "*4 + "*the password must be 6 characters or longer*")
while True:
login_password = input()
if len(login_password) >= 6:
add_user(create_user(
username, login_password))
print(
f"\nAccount for {username} has been successfully created.\nProceed to sign in.\n")
break
else:
print(
"\nThe password you entered is too short.")
print(
"Please use a password of 6 characters or more.")
continue
else:
print("\nThe username you entered is not valid.")
print(
"Please use alphabetical letters only with no spaces.")
continue
break
elif short_code == 'SI':
print("\nSIGN IN")
print("-"*7)
print("Enter your username")
username = input().strip(' ').capitalize()
print("Enter your password")
login_password = input().strip(' ')
if check_existing_user(username, login_password):
print("\nLog in successful")
print("What would you like to do?")
while True:
print("\nUse these short codes for navigation🤗 : \n CC: create new credentials \n FC: find a credential \n DC: delete a credential \n SC: see all credentials \n LO: log out")
credentials_navigation = input().upper()
if credentials_navigation == 'CC':
print("\nCREATE NEW CREDENTIALS")
print("-"*22)
while True:
print("Application name:")
print(" "*4 + "*eg. Twitter*")
application_name = input().capitalize().strip(' ')
if application_name != '':
print(
f"What is your current/desired username on {application_name}?")
account_username = input()
while True:
print(
f"\nDo you already have a password for your account on {application_name}? (Y/N)")
has_password = input().upper()
if has_password == 'Y':
print(
f"Enter your {application_name} password")
account_password = input()
add_credentials(create_credentials(
application_name, account_username, account_password))
print(
f"\nAccount credentials for your {application_name} account have been successfully saved.")
break
elif has_password == 'N':
while True:
print(
"Would you like a generated password? (Y/N)")
gen_pass = input().upper()
if gen_pass == 'Y':
print(
"How long would you like your password to be?")
print(" "*4 + "less than 8 characters: WEAK" + "\n" + " "*4 +
"8 characters: STRONG" + "\n" + " "*4 + "8-26 characters: VERY STRONG")
while True:
try:
passwordLength = int(
input())
if passwordLength in range(27):
account_password = generate_a_password(
passwordLength)
print(
f"Password generated is {account_password}")
add_credentials(create_credentials(
application_name, account_username, account_password))
print(
f"Account credentials for your {application_name} account have been successfully saved.\n")
break
except ValueError:
print(
"\nYou did not pick a valid password length")
print(
"Please pick a number between 0-26 and try again")
continue
elif gen_pass == 'N':
print(
f"Enter a password you wish to use for your {application_name} account")
print(
" "*4 + "*password must be longer than 6 characters*")
while True:
account_password = input()
if len(account_password) >= 6:
add_credentials(create_credentials(
application_name, account_username, account_password))
print(
f"Account credentials for your {application_name} have been successfully saved.\n")
break
else:
print(
"\nThe password you entered is too short.")
print(
"Please use a password of 6 characters or more.")
continue
else:
print(
"You did not select a valid option")
print(
"Please enter (Y/N) and try again")
continue
break
else:
print(
"You did not select a valid option")
print(
"Please enter (Y/N) and try again")
continue
break
break
else:
print(
"\nSorry, I didn't quite get the application name. Please try again.")
continue
elif credentials_navigation == 'FC':
if len(Credentials.credentials_list) >= 1:
print("\nFIND CREDENTIALS")
print("-"*16)
print(
"Enter the application whose credentials you'd like to find:")
print(" "*4 + "*eg. Twitter*")
searched_application = input().capitalize()
if check_existing_credentials(searched_application):
searched_credential = find_credentials(
searched_application)
print(
f"\nApplication name: {searched_credential.application_name}, \n username: {searched_credential.account_username} \n password: {searched_credential.account_password}")
else:
print(
f"\nThe credentials for {searched_application} don't exist.")
continue
else:
print(
"\nYou don't seem to have any credentials saved.")
continue
elif credentials_navigation == 'DC':
if len(Credentials.credentials_list) >= 1:
print("\nDELETE CREDENTIALS")
print("-"*18)
print("Application name:")
print(" "*4 + "*eg. Twitter*")
application_name = input().capitalize()
if check_existing_credentials(application_name):
while True:
print(
f"Are you sure you want to delete credentials for your {application_name}? (Y/N)")
delete_credential = input().upper()
if delete_credential == 'Y':
remove_credentials(
find_credentials(application_name))
print(
f"\nCredentials for {application_name} have been successfully deleted")
break
elif delete_credential == 'N':
print(
"\nPhew! Your credentials are still intact.")
break
else:
print(
"You did not select a valid option")
print(
"Please enter (Y/N) and try again\n")
continue
else:
print(
f"\nCredentials for {application_name} don't exist.")
continue
else:
print(
"\nYou don't seem to have any credentials saved.")
continue
elif credentials_navigation == 'SC':
if len(Credentials.credentials_list) >= 1:
display_credentials
print("\nHERE ARE ALL YOUR CREDENTIALS")
print("-"*29)
for credential in display_credentials():
print(
f"\nApplication name: {credential.application_name} \n Username: {credential.account_username} \n Password: {credential.account_password}")
continue
else:
print(
"\nYou don't seem to have any credentials saved.")
continue
elif credentials_navigation == 'LO':
print("\nYou have successfully logged out..\n")
break
else:
print("\nYou did not select a valid option.")
print("Please try again.")
continue
else:
print("\nInvalid username and password")
print("Try again or create an account\n")
continue
elif short_code == 'DA':
if len(Users.users_list) >= 1:
print("\nDELETE YOUR ACCOUNT")
print("-"*19)
print("Enter your username")
username = input().capitalize()
print("Enter your password")
login_password = input()
if check_existing_user(username, login_password):
while True:
print(
f"Are you sure you want to delete your account? (Y/N)")
delete_account = input().upper()
if delete_account == 'Y':
remove_user(find_user(username))
print(
f"\nYour account has been successfully deleted.\n")
break
elif delete_account == 'N':
print(
"\nPhew😌! Your account is still active.\n")
break
else:
print("You did not select a valid option")
print("Please enter (Y/N) and try again")
continue
else:
print(
"\nSeems like you do not have an active account or you entered the wrong details.")
print("Please try again.\n")
continue
else:
print(
"\nSorry, there are no active accounts at the moment.\n")
continue
elif short_code == 'EX':
print("\nBye👋....")
break
else:
print("\nYou did not select a valid option.")
print("Please try again.\n")
continue
else:
print("\nSorry, I didn't quite get your name. Please try again")
continue
break
if __name__ == '__main__':
main()