问题描述
我认为我的代码可以正常运行,但是当我从数据库中提取它时,我收到此错误“bcrypt.checkpw 错误 unicode 对象必须编码”
这是我的代码。这只是对数据库的基本提交,然后将它们拉出并使用 bcrypt 检查...
import sqlite3 as sl
def db_input(query):
connection = sl.connect("pword.db")
cursor = connection.cursor()
cursor.execute(query)
connection.commit()
connection.close()
def get_details():
name='ls'
password=b'hello'
hashed=bcrypt.hashpw(password,bcrypt.gensalt())
return name,hashed
def commit():
inputs=get_details()
query=f' insert into passwords(name,pword) values ("{inputs[0]}","{inputs[1]}")'
db_input(query)
def login():
name='ls'
password='hello'.encode()
connection = sl.connect("pword.db")
cursor = connection.cursor()
query=f"select pword from passwords where name ='{name}'"
cursor.execute(query)
result=cursor.fetchall()
connection.close()
print(result[0][0])
if bcrypt.checkpw(password,result[0][0]):
print('yes')
else: print('no')
commit()
login() ```
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)