-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_manager.py
More file actions
97 lines (85 loc) · 3.19 KB
/
password_manager.py
File metadata and controls
97 lines (85 loc) · 3.19 KB
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
#importing configs and credentials
from utils import config
from update import update
#from secret import get_secret_key
from menu import menu, create, find, find_accounts, delAccount
#importing the crypto module
from cryptography.fernet import Fernet
#functions to generate\load an encryption key
def generate_key():
key = Fernet.generate_key()
with open('secret.key','wb') as key_file:
key_file.write(key)
def load_key():
return open('secret.key','rb').read()
#functions to encrytpt and decrypt the password
def encrypt_pw(password):
key = load_key()
encoded_pw = password.encode()
f = Fernet(key)
encrypted_pw = f.encrypt(encoded_pw)
return encrypted_pw
def decrypt_pw(enc_password):
key = load_key()
f = Fernet(key)
decrypted_pw = f.decrypt(enc_password)
decoded_pw = decrypted_pw.decode()
return decoded_pw
#this function is run to see whether the programm has already been run and parse data from the config_file.txt file
def launch():
global launched
launched = False
if launched == config.islaunched:
generate_key()
global user_name,password,user,pw_db,dbname
print("---------------------------------------------------------")
print('Please Enter the masterUsername: ')
user_name = input('--> ')
print("---------------------------------------------------------")
password = encrypt_pw(input('Enter your password: \n--> '))
print("---------------------------------------------------------")
print('Enter the name of the user of your data base: ')
user = input('--> ')
print("---------------------------------------------------------")
print('The password of the data base: ')
pw_db = input('--> ')
print("---------------------------------------------------------")
print('Finally, the name of the data base: ')
dbname = input('--> ')
print("---------------------------------------------------------")
launched = True
args = ["islaunched","user_name","password","dbuser","dbname","dbpw"]
credentials = [launched,user_name, password,user,dbname, pw_db]
update(args,credentials)
else:
user_name = config.user_name
password = config.password
user = config.dbuser
pw_db = config.dbpw
dbname = config.dbname
return launched,user_name, password,user,pw_db,dbname
def run(n,p,a,b,c):
print("----------------------------------------------------------------------")
passw = input(f'Please provide the master password to start using {n}: ')
print("----------------------------------------------------------------------")
if passw == decrypt_pw(p):
print('You\'re in')
else:
print('no luck')
exit()
choice = menu()
while choice != 'Q':
if choice == '1':
create(a,b,c)
if choice == '2':
find_accounts(a,b,c)
if choice == '3':
find(a,b,c)
choice = menu()
elif choice == '4':
choice = delAccount(a, b, c)
else:
choice = menu()
#if __name__ == "__main__":
launch()
run(user_name, password,user,pw_db,dbname)