phase-1: data model, auth, permissions, masters, settings, seed
This commit is contained in:
@@ -1,18 +1,25 @@
|
||||
from datetime import timedelta
|
||||
import bcrypt
|
||||
from jose import JWTError, jwt
|
||||
from passlib.context import CryptContext
|
||||
from .config import settings
|
||||
from .time_utils import utc_now
|
||||
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||
|
||||
|
||||
def verify_password(plain: str, hashed: str) -> bool:
|
||||
return pwd_context.verify(plain, hashed)
|
||||
if not plain or not hashed:
|
||||
return False
|
||||
try:
|
||||
return bcrypt.checkpw(
|
||||
plain.encode("utf-8")[:72],
|
||||
hashed.encode("utf-8"),
|
||||
)
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
|
||||
def hash_password(plain: str) -> str:
|
||||
return pwd_context.hash(plain)
|
||||
hashed = bcrypt.hashpw(plain.encode("utf-8")[:72], bcrypt.gensalt())
|
||||
return hashed.decode("utf-8")
|
||||
|
||||
|
||||
def create_access_token(data: dict, expires_minutes: int | None = None) -> str:
|
||||
|
||||
Reference in New Issue
Block a user