forked from IMGIITRoorkee/PwManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
99 lines (80 loc) · 2.91 KB
/
main.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
from database import Database
from user_handler import UserHandler
from manager import PasswordManager
import pyperclip
def main():
db = Database()
session = db.get_session()
user_handler = UserHandler(session)
print("Welcome to the Multi-User Password Manager!")
current_user = None
while not current_user:
print("\n1. Register\n2. Login\nq. Quit")
choice = input("Enter choice: ").strip().lower()
if choice == '1':
username = input("Enter username: ").strip()
password = input("Enter password: ").strip()
try:
user_handler.register_user(username, password)
print("Registration successful!")
except:
print("Username already exists. Try a different one.")
elif choice == '2':
username = input("Enter username: ").strip()
password = input("Enter password: ").strip()
user = user_handler.authenticate_user(username, password)
if user:
print(f"Welcome, {username}!")
current_user = user
else:
print("Invalid credentials. Please try again.")
elif choice == 'q':
print("Goodbye!")
return
else:
print("Invalid choice. Try again.")
pm = PasswordManager(session, current_user)
while True:
print("""
1. List Available Keys
2. Select a Key
3. Add a New Key
4. Add Password (Using Selected Key)
5. Retrieve Password
6. List Sites
q. Quit
""")
choice = input("Enter choice: ").strip().lower()
if choice == '1':
pm.list_keys()
elif choice == '2':
keys = pm.list_keys()
if keys:
key_id = input("Enter the Key ID to select: ").strip()
pm.load_key(key_id)
elif choice == '3':
pm.add_new_key()
elif choice == '4':
path = input("Enter password file path: ").strip()
pm.load_password_file(path)
size = pm.get_file_size(path)
print(f"Password file loaded successfully. The size of is {size} bytes.")
if not pm.key:
print("Please select a key first.")
continue
site = input("Enter site name: ").strip()
password_value = input("Enter password: ").strip()
pm.add_password(site, password_value)
elif choice == '5':
site = input("Enter site name to retrieve password: ").strip()
password = pm.get_password(site)
print(f"Password for {site}: {password}")
elif choice == '6':
pm.list_sites()
elif choice == 'q':
print("Goodbye!")
break
else:
print("Invalid choice. Try again.")
if __name__ == "__main__":
main()