-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
130 lines (104 loc) · 4.76 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
#!/usr/bin/env python
import random
import string
from user import User
from credentials import Credentials
# functions to add credentials
def create_new_credential(account_name, account_password):
'''
method that creates new account name
'''
new_credential = Credentials(account_name, account_password)
return new_credential
def save_new_credential(credentials):
'''
method to save new credentials
'''
credentials.save_credentials()
def find_credential(account_name):
'''
method to find a credential that has been created
'''
return Credentials.find_by_name(account_name)
def generate_password(length=12):
"""Generate a random password."""
characters = string.ascii_letters + string.digits + string.punctuation
return ''.join(random.choice(characters) for i in range(length))
def main():
users = {} # Dictionary to store user credentials
print('\n')
while True:
print(
"******************** Welcome to password locker!!! ********************"
)
print('\n')
print("""Use these short codes to navigate: \n "nu"- add new user \n "lg"-login to your created account \n "ex"-to exit the system""")
short_code = input().lower()
print('\n')
if short_code == 'nu':
print('-----------create username---------')
created_user_name = input()
print('-----------create password---------')
created_user_password = input()
print('-----------confirm password---------')
confirm_password = input()
if created_user_password == confirm_password:
users[created_user_name] = created_user_password
print(f"User {created_user_name} created successfully!")
else:
print("Passwords do not match. Please try again.")
print('Do you want to create another user? (yes/no)')
create_another = input().lower()
if create_another == 'no':
continue # This will take you back to the main menu
elif short_code == 'lg':
print('-----------enter username---------')
username = input()
print('-----------enter password---------')
password = input()
if username in users and users[username] == password:
print(f"\nWelcome {username}!")
while True:
print("""Use these short codes to navigate: \n "cc"- create credential \n "dc"- display credentials \n "lo"- logout""")
user_short_code = input().lower()
if user_short_code == 'cc':
print('-----------enter account name---------')
account_name = input()
print('Do you want to create your own password or generate one? (c/g)')
password_option = input().lower()
if password_option == 'c':
print('-----------enter account password---------')
account_password = input()
elif password_option == 'g':
account_password = generate_password()
print("----------\n")
print(f"Generated password: {account_password}")
print("----------\n")
else:
print("Invalid option. Please try again.")
continue
new_credential = Credentials(account_name, account_password)
new_credential.save_credentials()
print(f"Credential for {account_name} created successfully!")
elif user_short_code == 'dc':
credentials = Credentials.display_credentials()
if credentials:
for credential in credentials:
print("----------")
print(f"Account: {credential.account_name}, Password: {credential.account_password}")
else:
print("\n----------No credentials found.----------\n")
elif user_short_code == 'lo':
print("Logging out...")
break
else:
print("Invalid short code. Please try again.")
else:
print("Invalid username or password. Please try again.")
elif short_code == 'ex':
print("Exiting the system...")
break
else:
print("Invalid short code. Please try again.")
if __name__ == '__main__':
main()