security_4.py 447 B

123456789101112131415161718
  1. def hash_pw(password):
  2. """
  3. Hashes the given password using scrypt and a random salt
  4. :param password: password to hash
  5. :returns: hashed password with arguments
  6. """
  7. salt = gen_rand_string()
  8. pw_hash = base64.b64encode(
  9. hmac.new(
  10. key=salt.encode('utf8'),
  11. msg=password.encode('utf8'),
  12. digestmod='SHA256'
  13. ).digest()
  14. ).decode('utf8')
  15. return implode(pw_hash, salt)