0
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)

How can i use pickle in python in order to add the username and password in dict and store it in file? dict included Hash file and i get an error as "TypeError: can't pickle _hashlib.HASH objects".

sasy
  • 1
  • 1
  • 1
    Possible duplicate of [Python add new item to dictionary](https://stackoverflow.com/questions/6416131/python-add-new-item-to-dictionary) – Red Cricket Nov 22 '18 at 03:51

1 Answers1

0

You have to call hexdigest method on your hashed password before pickling.
Like this:
dict = {username: {'SALT': salt, 'HASH': hash_code.hexdigest()}}

Logovskii Dmitrii
  • 2,629
  • 4
  • 27
  • 44