Spaces:
Paused
Paused
chih.yikuan Claude Opus 4.6 commited on
Commit ·
cd0918a
1
Parent(s): 459bded
Fix: Replace passlib with bcrypt directly to fix compatibility bug
Browse filespasslib has a known issue with newer bcrypt versions causing ValueError
on startup. Using bcrypt library directly avoids this entirely.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
chatkit/backend/app/auth.py
CHANGED
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
| 5 |
from datetime import datetime, timedelta
|
| 6 |
from typing import Optional
|
| 7 |
|
| 8 |
-
|
| 9 |
from jose import JWTError, jwt
|
| 10 |
from fastapi import Depends, HTTPException, status
|
| 11 |
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
|
@@ -13,16 +13,15 @@ from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
|
| 13 |
from .config import get_settings
|
| 14 |
from .database import get_user_by_email, get_user_by_id, create_user, update_last_login
|
| 15 |
|
| 16 |
-
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
| 17 |
security = HTTPBearer(auto_error=False)
|
| 18 |
|
| 19 |
|
| 20 |
def hash_password(password: str) -> str:
|
| 21 |
-
return
|
| 22 |
|
| 23 |
|
| 24 |
def verify_password(plain: str, hashed: str) -> bool:
|
| 25 |
-
return
|
| 26 |
|
| 27 |
|
| 28 |
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -> str:
|
|
|
|
| 5 |
from datetime import datetime, timedelta
|
| 6 |
from typing import Optional
|
| 7 |
|
| 8 |
+
import bcrypt
|
| 9 |
from jose import JWTError, jwt
|
| 10 |
from fastapi import Depends, HTTPException, status
|
| 11 |
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
|
|
|
| 13 |
from .config import get_settings
|
| 14 |
from .database import get_user_by_email, get_user_by_id, create_user, update_last_login
|
| 15 |
|
|
|
|
| 16 |
security = HTTPBearer(auto_error=False)
|
| 17 |
|
| 18 |
|
| 19 |
def hash_password(password: str) -> str:
|
| 20 |
+
return bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()).decode("utf-8")
|
| 21 |
|
| 22 |
|
| 23 |
def verify_password(plain: str, hashed: str) -> bool:
|
| 24 |
+
return bcrypt.checkpw(plain.encode("utf-8"), hashed.encode("utf-8"))
|
| 25 |
|
| 26 |
|
| 27 |
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -> str:
|
chatkit/backend/pyproject.toml
CHANGED
|
@@ -8,7 +8,7 @@ dependencies = [
|
|
| 8 |
"uvicorn[standard]>=0.36,<0.37",
|
| 9 |
"openai>=1.40",
|
| 10 |
"python-jose[cryptography]>=3.3.0",
|
| 11 |
-
"
|
| 12 |
"python-multipart>=0.0.6",
|
| 13 |
"python-dotenv>=1.0.0",
|
| 14 |
"aiosqlite>=0.19.0",
|
|
|
|
| 8 |
"uvicorn[standard]>=0.36,<0.37",
|
| 9 |
"openai>=1.40",
|
| 10 |
"python-jose[cryptography]>=3.3.0",
|
| 11 |
+
"bcrypt>=4.0.0",
|
| 12 |
"python-multipart>=0.0.6",
|
| 13 |
"python-dotenv>=1.0.0",
|
| 14 |
"aiosqlite>=0.19.0",
|