balance-application/util/auth_lib.py

17 lines
374 B
Python
Raw Permalink Normal View History

2024-09-10 05:20:11 +00:00
import base64
from hashlib import sha256
def hash(password: str, salt: str):
2024-09-10 08:08:06 +00:00
m = sha256()
m.update("{}:{}".format(password, salt).encode())
return m.hexdigest()
2024-09-10 05:20:11 +00:00
def gen_token(username: str, hashed_password: str):
raw = ("{}:{}".format(username, hashed_password)).encode("utf-8")
raw_token = base64.b64encode(raw)
token = raw_token.decode("ascii")
return token