![](/img/trans.png)
[英]Getting a password to matches with its hash in a login function using Python, SQlite and bcrypt
[英]Using an SQLite return as a password field within Bcrypt (Python)
我想檢查輸入的密碼是否與數據庫中存儲的密碼相同,但是當我使用bcrypt.checkpw()
時,它返回一個錯誤,指出它需要一個字符串或字節,因為 SQL 查詢返回一個元組。 我找不到將數據庫響應轉換為元組中的字節以使其兼容的方法。
sql = ''' SELECT password FROM user_data WHERE username=? '''
username = input('Input username: ')
password = bytes(input('Input Password: '), encoding='utf-8')
cur = conn.cursor()
cur.execute(sql, (username,))
rows = cur.fetchall()
for row in rows:
if bcrypt.checkpw(password, row):
details = (user_id, username, password)
print('logged in')
return details
break
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.