This code is supposed to hash a password with a salt. The salt and hashed password are being saved in the database. The password itself is not.
Given the sensitive nature of the operation, I wanted to make sure everything was properly executable.
import hashlib import base64 import uuid password = 'test_password' salt = base64.urlsafe_b64encode(uuid.uuid4().bytes) t_sha = hashlib.sha512() t_sha.update(password + salt) hashed_password = base64.urlsafe_b64encode(t_sha.digest())
t_sha.digest() + salt. You can split the salt out again later when you've decoded the salted hash password as you know the decoded hashed password is exactly 32 bytes.secretsinstead.