-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
82 lines (64 loc) · 2.26 KB
/
main.py
File metadata and controls
82 lines (64 loc) · 2.26 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
import sqlite3
# Connect to the database
con = sqlite3.connect("passwords.db")
cursor = con.cursor()
# Function to login to the system
def login():
name = input("Enter name: ")
master_password = input("Enter master password: ")
cursor.execute(f"SELECT * FROM master_login WHERE name=? AND master_password=?;", (name, master_password))
login_query = cursor.fetchone()
if login_query is None:
print("Login Fail")
login()
else:
print("\nLogin Successful!\n")
menu()
# Function to select options
def menu():
print("Type in the corresponding number to select an option")
print("1) View passwords")
print("2) Add a password")
print("3) Exit\n")
try:
choice = int(input())
if choice == 1:
view_passwords()
elif choice == 2:
add_password()
elif choice == 3:
exit()
except ValueError:
print("You can only type in numbers")
menu()
# Function to view available passwords
def view_passwords():
print("\n*-----------Your passwords-----------*\n")
for x in cursor.execute("SELECT website_name, url, username, email, notes, password FROM passwords;"):
website_name, url, username, email, notes, password = x
# Display the website name as a header
print(website_name)
print("-" * (len(website_name))) # Dynamic underline for readability
# Display each field with a title
print(f"URL: {url}")
print(f"Username: {username}")
print(f"Email: {email}")
print(f"Password: {password}")
print(f"Notes: {notes}")
print("\n") # Add space between entries
menu()
# Function to add a new password
def add_password():
print("\n*-----------Add a password to the database-----------*\n")
website_name = input("Website Name: ")
url = input("URL: ")
username = input("Username: ")
email = input("Email: ")
password = input("Password: ")
notes = input("Notes: ")
cursor.execute("INSERT INTO passwords (website_name, url, username, email, notes, password) VALUES (?, ?, ?, ?, ?, ?);", (website_name, url, username, email, notes, password))
con.commit()
print("\nInformation Added!\n")
menu()
login()
con.close()