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
print("\033[1;31;40m Error username or password.Plese try again\033[1;37;40m\n")
33
-
enter()
45
+
mysql_cursor=mydb.cursor(buffered=True)
46
+
id_cursor=mydb.cursor(buffered=True)
47
+
password_cursor=mydb.cursor(buffered=True)
48
+
salt_cursor=mydb.cursor(buffered=True)
49
+
db_setup()
50
+
51
+
defdb_setup():
52
+
# Check if Database exist
53
+
mysql_cursor.execute(f'CREATE DATABASE IF NOT EXISTS db_password_{login_user}')
54
+
55
+
# Check if Table exist
56
+
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
58
+
59
+
defmenu():
60
+
print('\nWelcome!')
61
+
print('v to view all your password')
62
+
print('i to insert new password')
63
+
print('d to delete password')
64
+
print('q to quit the program')
65
+
cmd=input('> ').lower()
66
+
67
+
ifcmd=='v':
68
+
view()
69
+
elifcmd=='i':
70
+
insert()
71
+
elifcmd=='d':
72
+
delete()
73
+
elifcmd=='q':
74
+
print('\nBye!')
75
+
return0
34
76
else:
35
-
#connect to database
36
-
mydb=mysql.connector.connect(
37
-
host='localhost', #or your hostname/ip-address
38
-
user=(enter.user),
39
-
password=(enter.passwd)
40
-
)
41
-
42
-
#set cursor
43
-
mycursor=mydb.cursor(buffered=True)
44
-
d=mydb.cursor(buffered=True)
45
-
i=mydb.cursor(buffered=True)
46
-
47
-
#detect and create database
48
-
mycursor.execute('CREATE DATABASE IF NOT EXISTS db_password')
49
-
mycursor.execute('CREATE TABLE IF NOT EXISTS db_password.tb_nap (id INT NOT NULL AUTO_INCREMENT,name VARCHAR(255) NOT NULL,password VARCHAR(255) NOT NULL,PRIMARY KEY (id))')
50
-
51
-
#interfaces
52
-
print("\n\nWelcome to password manager python! what you want to do?(v to view all your password,i to insert,d to delete,q to exit)")
53
-
cmd=input(">")
54
-
55
-
#view query
56
-
ifcmd=='v'orcmd=='V':
57
-
mycursor.execute("SELECT id, name FROM db_password.tb_nap") #select id,name from database
58
-
myresult=mycursor.fetchall()
59
-
60
-
iflen(myresult)==0: #detect blank input
61
-
print("Nothing here\n")
62
-
else:
63
-
print("What you wanna see?")
64
-
forxinmyresult :
65
-
print(x)
66
-
67
-
icmd=input("Enter ID:")
68
-
ificmd=='':
69
-
print("\033[1;31;40m Error id. \033[1;37;40m\n")
70
-
try:
71
-
icmd=int(icmd)
72
-
exceptValueError:
73
-
print("\033[1;31;40m Error id. \033[1;37;40m\n")
74
-
func()
75
-
else:
76
-
d.execute("SELECT id,name FROM db_password.tb_nap WHERE id= %s",(icmd,)) #select id,name from id input
77
-
i.execute("SELECT password FROM db_password.tb_nap WHERE id= %s",(icmd,)) #select password from id input
78
-
p=d.fetchall()
79
-
i=i.fetchall()
80
-
password=" , ".join( map(str, i) ) #transition list to string
81
-
82
-
k_encode=enter.k.encode() #encode key to byte
83
-
p_encode=password.encode() #encode password to byte
0 commit comments