mirror of
https://github.com/reconurge/flowsint.git
synced 2026-05-06 11:48:39 -05:00
26 lines
913 B
Python
26 lines
913 B
Python
from passlib.context import CryptContext
|
|
from datetime import datetime, timedelta
|
|
from jose import jwt
|
|
import os
|
|
from dotenv import load_dotenv
|
|
# Remplace avec ton URL de BDD
|
|
AUTH_SECRET = os.getenv("AUTH_SECRET")
|
|
|
|
load_dotenv()
|
|
ALGORITHM = "HS256"
|
|
ACCESS_TOKEN_EXPIRE_MINUTES = 60 * 60
|
|
|
|
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
|
|
|
def verify_password(plain_password: str, hashed_password: str) -> bool:
|
|
return pwd_context.verify(plain_password, hashed_password)
|
|
|
|
def get_password_hash(password: str) -> str:
|
|
return pwd_context.hash(password)
|
|
|
|
def create_access_token(data: dict, expires_delta: timedelta | None = None):
|
|
to_encode = data.copy()
|
|
expire = datetime.utcnow() + (expires_delta or timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES))
|
|
to_encode.update({"exp": expire})
|
|
encoded_jwt = jwt.encode(to_encode, AUTH_SECRET, algorithm=ALGORITHM)
|
|
return encoded_jwt |