diff --git a/backend/open_webui/utils/auth.py b/backend/open_webui/utils/auth.py index f941ef9263..e34803ade1 100644 --- a/backend/open_webui/utils/auth.py +++ b/backend/open_webui/utils/auth.py @@ -6,7 +6,7 @@ import hmac import hashlib import requests import os - +import bcrypt from cryptography.hazmat.primitives.ciphers.aead import AESGCM from cryptography.hazmat.primitives.asymmetric import ed25519 @@ -38,11 +38,8 @@ from open_webui.env import ( from fastapi import BackgroundTasks, Depends, HTTPException, Request, Response, status from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from passlib.context import CryptContext -logging.getLogger("passlib").setLevel(logging.ERROR) - log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["OAUTH"]) @@ -155,19 +152,25 @@ def get_license_data(app, key): bearer_security = HTTPBearer(auto_error=False) -pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") -def verify_password(plain_password, hashed_password): +def get_password_hash(password: str) -> str: + """Hash a password using bcrypt""" + return bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()).decode("utf-8") + + +def verify_password(plain_password: str, hashed_password: str) -> bool: + """Verify a password against its hash""" return ( - pwd_context.verify(plain_password, hashed_password) if hashed_password else None + bcrypt.checkpw( + plain_password.encode("utf-8"), + hashed_password.encode("utf-8"), + ) + if hashed_password + else None ) -def get_password_hash(password): - return pwd_context.hash(password) - - def create_token(data: dict, expires_delta: Union[timedelta, None] = None) -> str: payload = data.copy() diff --git a/backend/requirements.txt b/backend/requirements.txt index b1414e42b7..23e1300b49 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -6,9 +6,8 @@ itsdangerous==2.2.0 python-socketio==5.13.0 python-jose==3.4.0 -passlib[bcrypt]==1.7.4 cryptography -bcrypt==4.3.0 +bcrypt==5.0.0 argon2-cffi==25.1.0 PyJWT[crypto]==2.10.1 authlib==1.6.3 diff --git a/pyproject.toml b/pyproject.toml index 7378d3d287..47fde0b9cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,9 +14,8 @@ dependencies = [ "python-socketio==5.13.0", "python-jose==3.4.0", - "passlib[bcrypt]==1.7.4", "cryptography", - "bcrypt==4.3.0", + "bcrypt==5.0.0", "argon2-cffi==25.1.0", "PyJWT[crypto]==2.10.1", "authlib==1.6.3",