我试图找出如何将散列对象存储为字符串。 我有一段代码可以比较用户输入的内容与存储在Sqlite3数据库中的内容,然后允许他们访问或不访问,具体取决于用户名和密码是否正确。为了安全起见,我在数据库中对密码进行了哈希处理,并且用户输入的内容也是经过哈希处理的,它们是要进行比较的,但是当它进行检查时,它会给出shell中的行;
sqlite3-interfaceerror-error-binding-parameter-0-probably unsupported type
我被告知这是因为哈希不是字符串,所以我如何将哈希对象变成字符串?任何帮助,将不胜感激。谢谢,山姆。
此外,如果有帮助,这也是代码的完整部分。
def点击(按钮): 如果按钮==“取消”: login.stop()
if button == "Register":
login.stop()
register.go()
else:
usr = login.getEntry("Username")
pwd = login.getEntry("Password") #collects entry of password & username
###MD5 HASHING###
pwdencypt = hashlib.md5(pwd.encode('utf-8')) #makes the encypted password using md5 hashing
print(pwdencypt.hexdigest())
pwd2 = pwdencypt
conn = sqlite3.connect("uHubDatabase.db")
cursor = conn.cursor() #connects to database
###USERNAME SECTION###
find_user=("SELECT Username FROM UserTable WHERE Username = ?") #sets the finding of the username from the database as a varaible
cursor.execute(find_user,[(usr)])
founduser = str(cursor.fetchall())
print(founduser)
removechars = "'(),[]" #Avoids the error of special characters caused by the database outputting strings (Text)
for char in removechars:
founduser = founduser.replace(char,'')
###PASSWORD SECTION###
find_pass=("SELECT Password FROM UserTable WHERE Password = ?") #sets the finding of the password from the database as a varaible
cursor.execute(find_pass,[(pwd2)])
foundpass = str(cursor.fetchall())
print(foundpass)
removechars = "'(),[]" #Avoids the error of special characters caused by the database outputting strings (Text)
for char in removechars:
foundpass = foundpass.replace(char,'')
###DATA VARIABLE CHECKS###
print("This is from Database(Username)",founduser)
print("This is whats inputed",usr)
print("This is from Database(Password)",foundpass)
print("This is whats inputed",pwd)
print("This is pwd but encypted",pwdencypt.hexdigest())
if founduser == usr and foundpass == pwdencypt: # If correct
print("SUCESS")
login.stop()
home.go()
else: #if incorrect
print("FAIL")
login.retryBox("INCORRECT LOGIN", "The Username or Password entered are incorrect. Please try again.")
print("User:", usr, "Pass:", pwd)
conn.close() #closes connection
由于某种原因,当我将代码粘贴到此处时代码不对齐所以忽略它,在我的程序中不是这种情况。导入的模块包括sqlite3和Appjar,就像tkinter。