MarseyWorld/files/helpers/security.py

24 lines
433 B
Python
Raw Normal View History

2022-05-04 23:09:46 +00:00
from werkzeug.security import *
2022-07-08 16:21:13 +00:00
from .const import *
2022-05-04 23:09:46 +00:00
def generate_hash(string):
msg = bytes(string, "utf-16")
2022-10-10 09:06:27 +00:00
return hmac.new(key=bytes(SECRET_KEY, "utf-16"),
2022-05-04 23:09:46 +00:00
msg=msg,
digestmod='md5'
).hexdigest()
def validate_hash(string, hashstr):
return hmac.compare_digest(hashstr, generate_hash(string))
def hash_password(password):
return generate_password_hash(
password, method='pbkdf2:sha512', salt_length=8)