Files
service-finder/code-server-config/data/User/History/-6f62bdcf/gq3x.py

36 lines
1.4 KiB
Python
Executable File

import os
import bcrypt
from datetime import datetime, timedelta
from typing import Any, Union
from jose import jwt
# Titkosítási beállítások
SECRET_KEY = os.getenv("SECRET_KEY", "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7")
ALGORITHM = "HS256"
def verify_password(plain_password: str, hashed_password: str) -> bool:
"""Ellenőrzi a jelszót közvetlenül a bcrypt használatával."""
# A bcrypt byte-okat vár, ezért konvertáljuk le
password_bytes = plain_password.encode('utf-8')
hashed_bytes = hashed_password.encode('utf-8')
return bcrypt.checkpw(password_bytes, hashed_bytes)
def get_password_hash(password: str) -> str:
"""Létrehozza a jelszó hash-ét közvetlenül a bcrypt használatával."""
# Salt generálás és hash-elés
salt = bcrypt.gensalt()
password_bytes = password.encode('utf-8')
hashed = bcrypt.hashpw(password_bytes, salt)
return hashed.decode('utf-8')
def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None) -> str:
"""JWT token generálása."""
to_encode = data.copy()
if expires_delta:
expire = datetime.utcnow() + expires_delta
else:
expire = datetime.utcnow() + timedelta(minutes=1440)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt