【发布时间】:2015-10-28 14:52:56
【问题描述】:
在一个有用户和密码的小组程序上工作。我们正在尝试通过 python 将我们的用户和密码插入到 sqlite。但是 atm 我们只是在我们的图形窗口弹出一个应该发送数据的按钮之前发送空白数据。我们尝试了在多个网站上发现的不同变体,但似乎没有任何效果。
from tkinter import *
import sqlite3
import sys
conn = sqlite3.connect('indexCards.db')
cur = conn.cursor()
users ={}
def addUser(entUsername, entPassword):
#global entUsername, entPassword
NAME = entUsername.get()
PASSWORD = entPassword.get()
print("add User") #this is testing only
print(NAME, PASSWORD) # this is testing to see the passed variable
//
//This is where we are having the issues
conn.executemany('INSERT INTO USER(NAME,PASSWORD)\
VALUES (? ,?);', [(NAME,PASSWORD)])
conn.commit();
return (NAME, PASSWORD)
def makeWindow():
global entUsername, entPassword
window = Tk()
window.title('Add New User')
lblInst = Label(window, text = "Create your account here:", font=("Helvetica",16))
lblInst.pack()
lblUsername = Label(window, text="Please enter a username: ")
entUsername = Entry(window)
lblUsername.pack()
entUsername.pack()
lblPassword = Label(window, text="Please enter a password: ")
entPassword = Entry(window)
lblPassword.pack()
entPassword.pack()
btn = Button(window, text="Create", command=addUser(entUsername, entPassword))
btn.pack()
print (addUser(entUsername, entPassword))
print('entUsername', 'entPassword')
#window.mainloop()
return window
#if __name__ == '__main__':
# main():
window = makeWindow()
window.mainloop()
【问题讨论】:
-
conn.executemany('INSERT INTO USER(NAME,PASSWORD)\ VALUES (? ,?);', [(NAME,PASSWORD)])->conn.execute('INSERT INTO USER(NAME,PASSWORD) VALUES (? ,?);', (NAME,PASSWORD))。但是,您是否真的要将纯文本密码存储到数据库中? -
这个程序并不真正需要安全性,因为它只是一个类。我们真的不需要用户和密码,我只需要能够将信息发送到 sql 数据库而不是空白。