hisham-cmd commited on
Commit
90e323a
·
verified ·
1 Parent(s): 3e7da8c

Upload app/core/security.py

Browse files
Files changed (1) hide show
  1. app/core/security.py +8 -4
app/core/security.py CHANGED
@@ -2,22 +2,26 @@ from datetime import datetime, timedelta, timezone
2
  from typing import Optional
3
 
4
  from jose import JWTError, jwt
5
- from passlib.context import CryptContext
6
  from fastapi import Depends, HTTPException, status
7
  from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
8
 
9
  from app.core.config import settings
10
 
11
- pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
 
 
12
  security_scheme = HTTPBearer()
13
 
14
 
15
  def hash_password(password: str) -> str:
16
- return pwd_context.hash(password)
17
 
18
 
19
  def verify_password(plain_password: str, hashed_password: str) -> bool:
20
- return pwd_context.verify(plain_password, hashed_password)
 
 
 
21
 
22
 
23
  def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -> str:
 
2
  from typing import Optional
3
 
4
  from jose import JWTError, jwt
 
5
  from fastapi import Depends, HTTPException, status
6
  from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
7
 
8
  from app.core.config import settings
9
 
10
+ # Use bcrypt directly to avoid passlib/bcrypt version incompatibility
11
+ import bcrypt as _bcrypt
12
+
13
  security_scheme = HTTPBearer()
14
 
15
 
16
  def hash_password(password: str) -> str:
17
+ return _bcrypt.hashpw(password.encode("utf-8"), _bcrypt.gensalt()).decode("utf-8")
18
 
19
 
20
  def verify_password(plain_password: str, hashed_password: str) -> bool:
21
+ try:
22
+ return _bcrypt.checkpw(plain_password.encode("utf-8"), hashed_password.encode("utf-8"))
23
+ except Exception:
24
+ return False
25
 
26
 
27
  def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -> str: