-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword_manager.py
131 lines (101 loc) · 4.14 KB
/
password_manager.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
import os, secrets, sys, string, pyperclip
def exit_program():
sys.exit()
def create_random_password():
length = int(input("how many characters do you like"))
alphabet = string.ascii_letters + string.digits
password = ''.join(secrets.choice(alphabet) for i in range(length))
return password
def store_password(service, username, password):
with open ("password.txt", "a") as x:
x.write(f"service: {service}, username: {username}, password: {password}")
print('password is succesfully saved')
def does_file_exist():
if os.path.exists("password.txt"):
return True
else:
return False
def does_master_exist():
if os.path.exists('masterpasswd.txt'):
return True
else:
return False
def read_password():
with open("password.txt", "r") as xx:
return xx.read()
def copy(copied):
pyperclip.copy(copied)
print("copied")
def create_master(master):
with open("masterpasswd.txt", "w") as xxx:
xxx.write(master)
print("master password created")
return master
def read_master():
with open("masterpasswd.txt", "r") as xxxx:
return xxxx.read()
def delete_all_passwords():
os.remove("password.txt")
def delete_master():
os.remove("masterpasswd.txt")
def main():
if os.path.exists("masterpasswd.txt"):
masterpassword = input("what is your master password? \n")
if masterpassword == read_master():
print("master password is correct, what do you want to do?")
while True:
choice = int(input("1. store a password \n 2. see stored password \n 3. delete all passwords \n 4. delete all data including master password \n 5. exit program \n"))
if choice == 1:
username = input("enter your username \n")
service = input('enter a service \n')
choice2 = int(input('press 1 if you want to randomly generate a password \n'))
if choice2 == 1:
password = create_random_password()
else:
password = input('what is your password \n')
store_password(service, username, password)
elif choice == 2:
if does_file_exist():
print(read_password())
copy(read_password())
print('passwords copied')
else:
print('no passwords found')
elif choice == 3:
if does_file_exist():
delete_all_passwords()
print('passwords succesfully deleted')
else:
print('no passwords found')
elif choice == 4:
if does_file_exist() and does_master_exist():
delete_all_passwords()
delete_master()
print('passwords and master password succesfully deleted')
elif does_file_exist() == False and does_master_exist():
delete_master()
print('passwords deleted')
else:
print('no passwords found')
elif choice == 5:
exit_program()
else:
print("you entered the wrong password")
exit_program()
else:
choice3 = int(input('no master password found. would you like to #? press 1 or 0 \n'))
if choice3 == 1:
master = input('create a master password, 12 characters at least \n')
if len(master) < 12:
print("your master password may not be less than 12 characters")
print('exiting')
exit_program()
else:
create_master(master)
print('master password succesfully created. restarting the program.')
exit_program()
else:
print('exiting')
exit_program()
if __name__ == '__main__':
main()