-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·169 lines (150 loc) · 5.16 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
#!/usr/bin/env python3.6
import random
from credentials import credentials
from credentials import user
#methods for user
def create_user(name,pwd):
'''
function to create new user
'''
new_user = user(name,pwd)
return new_user
def save_user(user):
'''
function to save user details
'''
user.save_user()
def generate_password(user):
'''
function to generate password
'''
user.generate_password()
#methods for credentials
def create_account(account_name, user_name, password):
'''
function to create new account
'''
new_account = credentials(account_name, user_name, password)
return new_account
def save_account(account):
'''
function to save account
'''
account.save_account()
def del_account(account):
'''
function to delete account
'''
account.delete_account()
def find_account(account_name):
'''
function to find account by account name
'''
return credentials.find_by_account(account_name)
def check_existing_account(account_name):
'''
function that checks if account exists
'''
return credentials.account_exists(account_name)
def display_accounts():
'''
function that returns saved accounts
'''
return credentials.display_accounts()
def main():
print("<------welcome--to---Password Locker---->")
print('''Do you ever want to easily access your passwords
without having to memorize??
Well here is a chance to save all your passwords in a
single location''')
print("\n")
print("Enter your name here: ")
username = input()
print("*"*78)
print(f"Hello {username}.\nDo you want to enter a password or we automatically generate for you?")
print('''
Press:
g- generate new password
c- create your own password
''')
pwd_click = input()
if (pwd_click == 'g'):
chars = '1234567890abcdefghijklmnop?/@-' #characters to choose from
length = int(input("Enter the length of password you want: "))
pwdinput = ''
for c in range(length):
pwdinput += random.choice(chars) #generate random password
print (pwdinput)
print(f"{username} your password is {pwdinput}")
elif (pwd_click == 'c'):
print("enter your password: ")
pwdinput = input()
print(f"{username} your password is {pwdinput}")
print("\n"*2)
save_user(create_user(username,pwdinput))
#create and save user credentials
print('\n' * 2)
print (f"New user {username} created.")
print('\n' * 2)
print("To continue reenter your details")
print("*"*78)
print("Enter your username again: ")
name = input()
print("Enter your password: ")
pwd = input()
if (name == username and pwd == pwdinput):
print('\n')
while True:
print('''Use the following short codes:
c - create new account to save
d - display accounts saved
f - find saved account
ex - exit
''')
short_code = input().lower()
if short_code == 'c':
print("--------New account---------")
print("-"*80)
print("Account Name: ")
account_name = input()
print("User Name: ")
user_name = input()
print("Password for account: ")
password = input()
save_account(create_account(account_name,user_name,password))
#create and save account credentials
print('\n' * 1)
print (f"New account {account_name} created.")
print('\n' * 1)
elif short_code == 'd':
if display_accounts():
print("Here is a list of all your accounts: ")
print('\n')
for account in display_accounts():
print(f"{account.account_name} {account.user_name} {account.password}")
print('\n')
else:
print('\n')
print("You dont have any saved acccounts yet")
print('\n')
elif short_code == 'f':
print("Enter the name of the account you want to search for: ")
search_account_name = input()
if check_existing_account(search_account_name):
search_account = find_account(search_account_name)
print(f"{search_account.account_name}")
print('-' * 20)
print(f"User Name...................{search_account.user_name}")
print(f"Password...................{search_account.password}")
else:
print("Account does not exist")
elif short_code == 'ex':
print("Thanks for your time! Bye!")
break
else:
print("Sorry didnt get that! Please use the short codes")
else:
print('''Incorrect Name or Password
Run the application again''')
if __name__ == '__main__':
main()