-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·161 lines (141 loc) · 4.64 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
#! /usr/bin/env python3
import pyperclip
from locker import User, Credential
def create_user(fname,lname,password):
'''
Function to create a new user account
'''
new_user = User(fname,lname,password)
return new_user
def save_user(user):
'''
Function to save a new user account
'''
User.save_user(user)
def verify_user(first_name,password):
'''
Function that verifies the existance of the user before creating credentials
'''
checking_user = Credential.check_user(first_name,password)
return checking_user
def generate_password():
'''
Function to generate a password automatically
'''
gen_pass = Credential.generate_password()
return gen_pass
def create_credential(user_name,site_name,account_name,password):
'''
Function to create a new credential
'''
new_credential=Credential(user_name,site_name,account_name,password)
return new_credential
def save_credential(credential):
'''
Function to save a newly created credential
'''
Credential.save_credentials(credential)
def display_credentials(user_name):
'''
Function to display credentials saved by a user
'''
return Credential.display_credentials(user_name)
def copy_credential(site_name):
'''
Function to copy a credentials details to the clipboard
'''
return Credential.copy_credential(site_name)
def main():
print(' ')
print('Hello! Welcome to Password Locker.')
while True:
print(' ')
print("-"*60)
print('Use these codes to navigate: \n ca-Create an Account \n li-Log In \n ex-Exit')
short_code = input('Enter a choice: ').lower().strip()
if short_code == 'ex':
break
elif short_code == 'ca':
print("-"*60)
print(' ')
print('To create a new account:')
first_name = input('Enter your first name - ').strip()
last_name = input('Enter your last name - ').strip()
password = input('Enter your password - ').strip()
save_user(create_user(first_name,last_name,password))
print(" ")
print(f'New Account Created for: {first_name} {last_name} using password: {password}')
elif short_code == 'li':
print("-"*60)
print(' ')
print('To login, enter your account details:')
user_name = input('Enter your first name - ').strip()
password = str(input('Enter your password - '))
user_exists = verify_user(user_name,password)
if user_exists == user_name:
print(" ")
print(f'Welcome {user_name}. Please choose an option to continue.')
print(' ')
while True:
print("-"*60)
print('Navigation codes: \n cc-Create a Credential \n dc-Display Credentials \n copy-Copy Password \n ex-Exit')
short_code = input('Enter a choice: ').lower().strip()
print("-"*60)
if short_code == 'ex':
print(" ")
print(f'Goodbye {user_name}')
break
elif short_code == 'cc':
print(' ')
print('Enter your credential details:')
site_name = input('Enter the site\'s name- ').strip()
account_name = input('Enter your account\'s name - ').strip()
while True:
print(' ')
print("-"*60)
print('Please choose an option for entering a password: \n ep-enter existing password \n gp-generate a password \n ex-exit')
psw_choice = input('Enter an option: ').lower().strip()
print("-"*60)
if psw_choice == 'ep':
print(" ")
password = input('Enter your password: ').strip()
break
elif psw_choice == 'gp':
password = generate_password()
break
elif psw_choice == 'ex':
break
else:
print('Oops! Wrong option entered. Try again.')
save_credential(create_credential(user_name,site_name,account_name,password))
print(' ')
print(f'Credential Created: Site Name: {site_name} - Account Name: {account_name} - Password: {password}')
print(' ')
elif short_code == 'dc':
print(' ')
if display_credentials(user_name):
print('Here is a list of all your credentials')
print(' ')
for credential in display_credentials(user_name):
print(f'Site Name: {credential.site_name} - Account Name: {credential.account_name} - Password: {credential.password}')
print(' ')
else:
print(' ')
print("You don't seem to have any credentials saved yet")
print(' ')
elif short_code == 'copy':
print(' ')
chosen_site = input('Enter the site name for the credential password to copy: ')
copy_credential(chosen_site)
print('')
else:
print('Oops! Wrong option entered. Try again.')
else:
print(' ')
print('Oops! Wrong details entered. Try again or Create an Account.')
else:
print("-"*60)
print(' ')
print('Oops! Wrong option entered. Try again.')
if __name__ == '__main__':
main()