【发布时间】:2022-12-18 01:32:46
【问题描述】:
我正在创建一个登录功能,其中一部分包括检查用户输入的密码与存储在数据库中的密码。
问题是,当在注册步骤中创建密码时,它使用 fernet 存储为加密字符串。现在我试着看看用相同的密钥加密用户输入的密码是否会产生与数据库中相同的加密字符串值,但是 fernet 将在相同的明文上使用相同的密钥创建唯一的字符串。
还有什么其他方法可以检查输入的密码与数据库中的加密对应密码?
import sqlite3
from cryptography.fernet import Fernet
key = Fernet.generate_key()
fernet = Fernet(key)
def loginFunc():
email = input("What is your email: ")
password = input("what is your password: ")
#a variable that can be used to save the data from users database
emailList = '''SELECT * FROM users WHERE `email` = ? and `password` = ?'''
#takes arguments into variable
password_checkEnc = fernet.encrypt(password.encode())
inputs = (email, password_checkEnc)
#executes line 62 to save the data that matches the arguments from 'inputs' and stores in emailList
cursor.execute(emailList, inputs)
user = cursor.fetchone()
#if statement to check if the database holds the data that is being searched for, allowing either the user to login or not
if user is not None:
print("login successful")
else:
print("incorrect information")
【问题讨论】:
标签: python sqlite encryption fernet