From c4d80fd3853ca409e0dc26534ffb01a837e6edf1 Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Wed, 6 Mar 2024 22:42:37 +0100 Subject: [PATCH] fix for https://github.com/Kozea/Radicale/issues/1350 replacing passlib[bcrypt] with direct call to bcrypt --- config | 2 +- radicale/auth/htpasswd.py | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/config b/config index cfd7412e..4f344387 100644 --- a/config +++ b/config @@ -60,7 +60,7 @@ # Htpasswd encryption method # Value: plain | bcrypt | md5 -# bcrypt requires the installation of radicale[bcrypt]. +# bcrypt requires the installation of 'bcrypt' module. #htpasswd_encryption = md5 # Incorrect authentication delay (seconds) diff --git a/radicale/auth/htpasswd.py b/radicale/auth/htpasswd.py index 872f7277..dbc40b91 100644 --- a/radicale/auth/htpasswd.py +++ b/radicale/auth/htpasswd.py @@ -73,15 +73,11 @@ class Auth(auth.BaseAuth): self._verify = self._md5apr1 elif encryption == "bcrypt": try: - from passlib.hash import bcrypt + import bcrypt except ImportError as e: raise RuntimeError( "The htpasswd encryption method 'bcrypt' requires " - "the passlib[bcrypt] module.") from e - # A call to `encrypt` raises passlib.exc.MissingBackendError with a - # good error message if bcrypt backend is not available. Trigger - # this here. - bcrypt.hash("test-bcrypt-backend") + "the bcrypt module.") from e self._verify = functools.partial(self._bcrypt, bcrypt) else: raise RuntimeError("The htpasswd encryption method %r is not " @@ -92,7 +88,7 @@ class Auth(auth.BaseAuth): return hmac.compare_digest(hash_value.encode(), password.encode()) def _bcrypt(self, bcrypt: Any, hash_value: str, password: str) -> bool: - return bcrypt.verify(password, hash_value.strip()) + return bcrypt.checkpw(password = password.encode('utf-8'), hashed_password = hash_value.encode()) def _md5apr1(self, hash_value: str, password: str) -> bool: return apr_md5_crypt.verify(password, hash_value.strip())