ScamDetect Bot commited on
Commit
f225ab8
·
1 Parent(s): ed8044d

Auto-sync backend and fix configuration

Browse files
backend/api/routes/auth.py CHANGED
@@ -3,7 +3,7 @@ from typing import Optional
3
  from fastapi import APIRouter, Depends, HTTPException, status
4
  from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
5
  from jose import JWTError, jwt
6
- from passlib.context import CryptContext
7
  from sqlalchemy.orm import Session
8
 
9
  from database import get_db
@@ -19,16 +19,19 @@ GOOGLE_CLIENT_ID = os.getenv("GOOGLE_CLIENT_ID", "YOUR_GOOGLE_CLIENT_ID")
19
  ALGORITHM = "HS256"
20
  ACCESS_TOKEN_EXPIRE_MINUTES = 60 * 24 * 7 # 1 week
21
 
22
- pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
23
  oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/auth/login", auto_error=False)
24
 
25
  router = APIRouter(prefix="/auth", tags=["Authentication"])
26
 
27
- def verify_password(plain_password, hashed_password):
28
- return pwd_context.verify(plain_password, hashed_password)
 
 
 
 
29
 
30
- def get_password_hash(password):
31
- return pwd_context.hash(password)
32
 
33
  def create_access_token(data: dict, expires_delta: Optional[timedelta] = None):
34
  to_encode = data.copy()
 
3
  from fastapi import APIRouter, Depends, HTTPException, status
4
  from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
5
  from jose import JWTError, jwt
6
+ import bcrypt
7
  from sqlalchemy.orm import Session
8
 
9
  from database import get_db
 
19
  ALGORITHM = "HS256"
20
  ACCESS_TOKEN_EXPIRE_MINUTES = 60 * 24 * 7 # 1 week
21
 
 
22
  oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/auth/login", auto_error=False)
23
 
24
  router = APIRouter(prefix="/auth", tags=["Authentication"])
25
 
26
+ def verify_password(plain_password: str, hashed_password: str) -> bool:
27
+ # Handle the case where passlib originally generated the hash
28
+ try:
29
+ return bcrypt.checkpw(plain_password.encode('utf-8'), hashed_password.encode('utf-8'))
30
+ except ValueError:
31
+ return False
32
 
33
+ def get_password_hash(password: str) -> str:
34
+ return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
35
 
36
  def create_access_token(data: dict, expires_delta: Optional[timedelta] = None):
37
  to_encode = data.copy()
backend/requirements.txt CHANGED
@@ -43,7 +43,6 @@ evaluate>=0.4.0
43
  # Utilities
44
  python-dotenv>=1.0.0
45
  python-jose>=3.3.0
46
- passlib>=1.7.4
47
  bcrypt>=4.1.2
48
  email-validator>=2.1.0
49
  google-auth>=2.23.0
 
43
  # Utilities
44
  python-dotenv>=1.0.0
45
  python-jose>=3.3.0
 
46
  bcrypt>=4.1.2
47
  email-validator>=2.1.0
48
  google-auth>=2.23.0