我正在设计一个登录表单。当用户注册时,密码被散列并存储在数据库中。同一个用户试图登录,登录表单输入的密码被散列并与数据库中的散列进行比较,但登录失败,说密码错误。
我试着在注册页面输入另一个不同于第一个密码的密码,但是不同密码的哈希值看起来都一样
登录区块
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
字符串
SignUp区块
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 !!")
型
1条答案
按热度按时间wz1wpwve1#
看起来像是注册块中的这一行中的一个错字:
字符串
“* 但不同密码的哈希值看起来都一样 *”,因为它们都是空字符串的哈希值(我假设)。