Fix bcrypt password verification error
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
- Added fallback to use bcrypt directly in verify_password - Ensures password verification works despite passlib version conflicts - Both hash and verify now handle bcrypt compatibility issue
This commit is contained in:
parent
c29f4af574
commit
e4d37dea3f
@ -14,11 +14,29 @@ security = HTTPBearer()
|
|||||||
|
|
||||||
|
|
||||||
def verify_password(plain_password: str, hashed_password: str) -> bool:
|
def verify_password(plain_password: str, hashed_password: str) -> bool:
|
||||||
return pwd_context.verify(plain_password, hashed_password)
|
try:
|
||||||
|
return pwd_context.verify(plain_password, hashed_password)
|
||||||
|
except ValueError as e:
|
||||||
|
if "password cannot be longer than 72 bytes" in str(e):
|
||||||
|
# Fallback: use bcrypt directly to avoid passlib version issues
|
||||||
|
import bcrypt
|
||||||
|
return bcrypt.checkpw(
|
||||||
|
plain_password.encode('utf-8'),
|
||||||
|
hashed_password.encode('utf-8')
|
||||||
|
)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
def get_password_hash(password: str) -> str:
|
def get_password_hash(password: str) -> str:
|
||||||
return pwd_context.hash(password)
|
try:
|
||||||
|
return pwd_context.hash(password)
|
||||||
|
except Exception as e:
|
||||||
|
# Fallback: use bcrypt directly to avoid passlib version issues
|
||||||
|
import bcrypt
|
||||||
|
return bcrypt.hashpw(
|
||||||
|
password.encode('utf-8'),
|
||||||
|
bcrypt.gensalt()
|
||||||
|
).decode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -> str:
|
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -> str:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user