31 lines
778 B
Python
31 lines
778 B
Python
import os
|
|
from dotenv import load_dotenv
|
|
from sqlalchemy.orm import sessionmaker
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import declarative_base
|
|
from passlib.context import CryptContext
|
|
|
|
# Load environment variables
|
|
load_dotenv()
|
|
|
|
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://postgres:postgres@localhost:5432/postgres")
|
|
|
|
engine = create_engine(DATABASE_URL)
|
|
SessionLocal = sessionmaker(bind=engine)
|
|
Base = declarative_base()
|
|
|
|
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
|
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
def hash_password(pw: str) -> str:
|
|
return pwd_context.hash(pw)
|
|
|
|
def verify_password(pw: str, hashed: str) -> bool:
|
|
return pwd_context.verify(pw, hashed)
|