import hashlib
import uuid
def ask_pass():
username = input("create your username: ")
password = input("create your password: ")
salt = uuid.uuid4().hex
hash_code = hashlib.sha256(salt.encode() + password.encode())
dict = {
username: {
'SALT': salt,
'HASH': hash_code
}
}
with open("file.pkl", "wb") as f:
pickle.dump(dict, f)
我如何在python中使用pickle以便在dict中添加用户名和密码并将其存储在文件中? dict包含哈希文件,并且出现错误“ TypeError:无法腌制_hashlib.HASH对象”。
答案 0 :(得分:0)
在腌制之前,必须对哈希密码调用hexdigest方法。
像这样:
dict = {username: {'SALT': salt, 'HASH': hash_code.hexdigest()}}