mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 04:23:01 +00:00
b40f05cc7c
+ rewrite migrations logic + rename encode_password to hash_password + update image sizes (add medium size) + rename image endpoints
32 lines
755 B
Python
32 lines
755 B
Python
import hmac
|
|
import hashlib
|
|
|
|
from app.config import UserConfig
|
|
|
|
|
|
def hash_password(password: str) -> str:
|
|
"""
|
|
Hashes the given password using sha256 algorithm and the user id as salt.
|
|
|
|
:param password: The password to hash.
|
|
|
|
:return: The hashed password.
|
|
"""
|
|
|
|
return hashlib.pbkdf2_hmac(
|
|
"sha256", password.encode("utf-8"), UserConfig().userId.encode("utf-8"), 100000
|
|
).hex()
|
|
|
|
|
|
def check_password(password: str, hashed: str) -> bool:
|
|
"""
|
|
This function checks if the given password matches the hashed password.
|
|
|
|
:param password: The password to check.
|
|
:param hashed: The hashed password.
|
|
|
|
:return: Whether the password matches.
|
|
"""
|
|
|
|
return hmac.compare_digest(hash_password(password), hashed)
|