You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
main_passwd=getpass.getpass('Enter main password: ')
38
39
39
40
# Database connection
40
-
mydb=mysql.connector.connect(
41
-
host='localhost', # Change this if you have dedicated Database
42
-
user=(login_user),
43
-
password=(mysql_passwd)
44
-
)
41
+
try:
42
+
mydb=mysql.connector.connect(
43
+
host='localhost', # Change this if you have dedicated Database
44
+
user=(login_user),
45
+
password=(mysql_passwd)
46
+
)
47
+
exceptmysql.connector.Erroraserr:
48
+
print(f"\nCan't connect to Database, error: {err}")
49
+
exit(1)
45
50
mysql_cursor=mydb.cursor(buffered=True)
46
51
id_cursor=mydb.cursor(buffered=True)
47
52
password_cursor=mydb.cursor(buffered=True)
48
53
salt_cursor=mydb.cursor(buffered=True)
49
-
db_setup()
54
+
returndb_setup()
50
55
51
56
defdb_setup():
52
57
# Check if Database exist
53
58
mysql_cursor.execute(f'CREATE DATABASE IF NOT EXISTS db_password_{login_user}')
54
59
55
60
# Check if Table exist
56
61
mysql_cursor.execute(f'CREATE TABLE IF NOT EXISTS db_password_{login_user}.tb_{login_user} (id INT NOT NULL AUTO_INCREMENT,name VARCHAR(255) NOT NULL,tag VARCHAR(255), password BLOB NOT NULL, salt BLOB NOT NULL, PRIMARY KEY (id))')
57
-
menu() # Forward to menu
62
+
returnmenu() # Forward to menu
58
63
59
64
defmenu():
60
65
print('\nWelcome!')
@@ -65,30 +70,34 @@ def menu():
65
70
cmd=input('> ').lower()
66
71
67
72
ifcmd=='v':
68
-
view()
73
+
returnview()
69
74
elifcmd=='i':
70
-
insert()
75
+
returninsert()
71
76
elifcmd=='d':
72
-
delete()
77
+
returndelete()
73
78
elifcmd=='q':
74
79
print('\nBye!')
75
-
return0
80
+
exit(0)
76
81
else:
77
82
print('\nNot an option!')
78
83
returnmenu()
79
84
80
85
defdb_check():
81
-
# Query id, name
82
-
mysql_cursor.execute(f"SELECT id, name FROM db_password_{login_user}.tb_{login_user}")
83
-
myresult=mysql_cursor.fetchall()
84
-
85
-
# If query return 0
86
-
iflen(myresult) ==0:
87
-
print('Nothing to show.')
88
-
else: # If there's data
89
-
foriteminmyresult:
90
-
print(item)
91
-
pass
86
+
try:
87
+
# Query id, name
88
+
mysql_cursor.execute(f"SELECT id, name FROM db_password_{login_user}.tb_{login_user}")
89
+
myresult=mysql_cursor.fetchall()
90
+
# If query return 0
91
+
iflen(myresult) ==0:
92
+
print('Nothing to show.')
93
+
returnmenu()
94
+
else: # If there's data
95
+
foriteminmyresult:
96
+
print(item)
97
+
pass
98
+
exceptmysql.connector.Erroraserr:
99
+
print(f'Error query data from database, error: {err}')
100
+
exit(1)
92
101
93
102
defview():
94
103
db_check()
@@ -105,6 +114,7 @@ def view():
105
114
returnview()
106
115
except:
107
116
print('\nInvalid ID')
117
+
returnview()
108
118
109
119
# Query id, name, salt, password
110
120
id_cursor.execute(f"SELECT id,name FROM db_password_{login_user}.tb_{login_user} WHERE id={view_id}")
0 commit comments