我正在设计一个登录表单。当用户注册时,密码被散列并存储在数据库中同一用户尝试登录,并且在登录表单中输入的密码被散列并与数据库中的散列进行比较,但登录失败,提示密码错误。
我尝试在注册页面上输入与第一个密码不同的另一个密码,但不同密码的哈希值看起来很相似
def handle_connection(self):
self.username = self.username.get()
self.password = self.password.get()
self.password = hashlib.sha256(self.password.encode()).hexdigest()
conn = sqlite3.connect("userdata.db")
cur = conn.cursor()
root.after(1000,)
# NUMBER OF ATTEMPTS ALLOWED
max_attempts = 5
attempts = 0
while True:
cur.execute("SELECT * FROM userdata WHERE username = ? AND password = ?", (self.username, self.password))
if cur.fetchall():
messagebox.showinfo("Login Successful !")
break
else:
messagebox.showerror("Login Failed !", "Wrong password or username !\n Please try again !")
break
def check_sign_up(self):
conn = sqlite3.connect("userdata.db")
cur = conn.cursor()
if self.password2.get() == self.password1.get() and self.email.get() != "":
self.password1 = hashlib.sha256(self.password.get().encode()).hexdigest()
cur.execute("INSERT INTO userdata (username, password, Email) VALUES (?,?,?)",
(self.username.get(), self.password1, self.email.get()))
conn.commit()
messagebox.showinfo("SUCCESS", "Thank you for Joining the Light Technologies")
else:
messagebox.showerror("E R R O R", "All fields are required !!")