我创建了一个哈希代码,但它返回不同输入的哈希值

问题描述 投票:0回答:1

我正在设计一个登录表单。当用户注册时,密码被散列并存储在数据库中同一用户尝试登录,并且在登录表单中输入的密码被散列并与数据库中的散列进行比较,但登录失败,提示密码错误。

我尝试在注册页面上输入与第一个密码不同的另一个密码,但不同密码的哈希值看起来很相似

登录区块

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 !!")
database sqlite authentication tkinter hash
1个回答
0
投票

注册块中的这一行看起来像是拼写错误:

self.password1 = hashlib.sha256(self.password.get().encode()).hexdigest()

但是不同密码的哈希值看起来很相似”,因为它们都是 哈希

None

© www.soinside.com 2019 - 2024. All rights reserved.