Skip to content

Commit 646017b

Browse files
committed
Adding Backend File
1 parent 90b2c36 commit 646017b

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎assets/backend/auth.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
from datetime import datetime, timedelta
3+
from typing import Optional
4+
5+
from jose import JWTError, jwt
6+
from passlib.context import CryptContext
7+
8+
# In production, use environment variables for the secret key
9+
SECRET_KEY = "your-very-secret-key-for-dashboard-development"
10+
ALGORITHM = "HS256"
11+
ACCESS_TOKEN_EXPIRE_MINUTES = 30
12+
13+
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
14+
15+
def verify_password(plain_password, hashed_password):
16+
return pwd_context.verify(plain_password, hashed_password)
17+
18+
def get_password_hash(password):
19+
return pwd_context.hash(password)
20+
21+
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None):
22+
to_encode = data.copy()
23+
if expires_delta:
24+
expire = datetime.utcnow() + expires_delta
25+
else:
26+
expire = datetime.utcnow() + timedelta(minutes=15)
27+
to_encode.update({"exp": expire})
28+
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
29+
return encoded_jwt

0 commit comments

Comments
 (0)