我正在用python做家庭助理,这是学习python的下一步。登录名将输入的密码转换为哈希。然后将散列的密码存储到单独的文本文件中。稍后在我的程序中检查登录时密码是否匹配时,会收到此错误消息。确切的错误消息是“ TypeError:'in'需要将字符串作为左操作数,而不是_hashlib.HASH”。任何帮助将是巨大的。在过去的三个小时中,我一直试图弄清楚这一点。谢谢!
帐户创建阶段:
password = input("Enter a password: ")
password1 = input("Please reenter your password: ")
if password1 == password:
print("Thank you for creating an account!")
with open("passwords.txt", "a")as f:
hashed_password_object = hashlib.md5(str.encode(password))
f.write(hashed_password_object.hexdigest())
str(f)
登录阶段:
login_password = input("Please enter your password: ")
login_password1 = hashlib.md5(str.encode(login_password))
login_password1.hexdigest()
str(login_password1)
with open('passwords.txt') as e:
if login_password1 in e.read():
print("Login successful. Welcome to your personal home assistant,
JIM.")
elif login_password1 is not e.read():
print("You got your password wrong you idiot.")