Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import hashlib
- from typing import Tuple
- HASH_NAME = "sha256"
- ITERATIONS = 100_000
- def gen_salt() -> bytes:
- return os.urandom(32)
- def hash_password(salt: bytes, password: str) -> bytes:
- """
- Generate a key for password using provided salt
- :param salt:
- :param password:
- :return:
- """
- new_key: bytes = hashlib.pbkdf2_hmac(HASH_NAME, password.encode("utf-8"), salt, ITERATIONS)
- return new_key
- def create_new_password(password: str) -> Tuple[bytes, bytes]:
- """
- Creates new salt and hashes passed password
- Returned tuple contains the key (hash) and salt
- :param password:
- :return:
- """
- salt = gen_salt()
- new_key = hash_password(salt, password)
- return new_key, salt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement