-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
125 lines (96 loc) · 4.14 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
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
# Fergus Haak - 31/07/2023 - main - Password Manager Program
# main.py
from passwordmanager.passwordmanager import PasswordManager
from passwordmanager.encryption import generate_key
def main():
# Create an instance of the PasswordManager class
password_manager = PasswordManager()
encryption_key = password_manager.load_encryption_key("../data/key.pkl")
while True:
choice = get_choice()
if choice == 0:
print("Exiting the program.")
break
elif choice == 1:
create_entry(password_manager)
elif choice == 2:
delete_entry(password_manager)
elif choice == 3:
edit_entry(password_manager)
elif choice == 4:
search_entries(password_manager)
elif choice == 5:
save_entries(password_manager, encryption_key)
elif choice == 6:
load_entries(password_manager, encryption_key)
elif choice == 7:
export_entries(password_manager)
else:
print("Invalid choice. Please try again.")
def get_choice():
print("\nMenu:")
print("1. Create Entry")
print("2. Delete Entry")
print("3. Edit Entry")
print("4. Search Entries")
print("5. Save Entries")
print("6. Load Entries")
print("7. Export Entries")
print("0. Exit")
while True:
try:
choice = int(input("Enter your choice: "))
return choice
except ValueError:
print("Invalid choice. Please enter a number.")
def create_entry(password_manager):
entry_data = {}
entry_data["type"] = input("Enter entry type (Login/Credit Card): ").title()
entry_data["id"] = int(input("Enter entry ID: "))
entry_data["username"] = input("Enter username: ")
entry_data["password"] = input("Enter password: ")
if entry_data["type"] == "Login":
entry_data["website"] = input("Enter website: ")
elif entry_data["type"] == "Credit Card":
entry_data["cardholder_name"] = input("Enter cardholder name: ")
entry_data["card_number"] = input("Enter card number: ")
entry_data["expiration_date"] = input("Enter expiration date: ")
entry_data["cvv"] = input("Enter CVV: ")
password_manager.create_entry(entry_data)
def delete_entry(password_manager):
entry_id = int(input("Enter the ID of the entry to delete: "))
password_manager.delete_entry(entry_id)
def edit_entry(password_manager):
entry_id = int(input("Enter the ID of the entry to edit: "))
entry = password_manager.find_id(entry_id)
if entry:
new_data = {}
new_data["username"] = input("Enter new username (leave empty to keep the same): ")
new_data["password"] = input("Enter new password (leave empty to keep the same): ")
if entry.get_type() == "Login":
new_data["website"] = input("Enter new website (leave empty to keep the same): ")
elif entry.get_type() == "Credit Card":
new_data["cardholder_name"] = input("Enter new cardholder name (leave empty to keep the same): ")
new_data["card_number"] = input("Enter new card number (leave empty to keep the same): ")
new_data["expiration_date"] = input("Enter new expiration date (leave empty to keep the same): ")
new_data["cvv"] = input("Enter new CVV (leave empty to keep the same): ")
password_manager.edit_entry(entry_id, new_data)
else:
print(f"Entry with ID {entry_id} not found.")
def search_entries(password_manager):
query = input("Enter the search query: ")
results = password_manager.search(query)
if results:
print("\nSearch Results:")
for entry in results:
print(entry.get_credentials())
else:
print("No matching entries found.")
def save_entries(password_manager, encryption_key):
password_manager.save_entries("../data/passwords.pkl", encryption_key)
def load_entries(password_manager, encryption_key):
password_manager.load_entries("../data/passwords.pkl", encryption_key)
def export_entries(password_manager):
password_manager.export_to_csv("../data/exported.csv")
if __name__ == "__main__":
main()