Skip to content

Commit

Permalink
Merge pull request #1404 from pbiering/fix-1350
Browse files Browse the repository at this point in the history
fix for #1350
  • Loading branch information
pbiering authored Mar 6, 2024
2 parents 96a4927 + 1593742 commit dfaef5d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 3 additions & 7 deletions radicale/auth/htpasswd.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,11 @@ def __init__(self, configuration: config.Configuration) -> None:
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 "
Expand All @@ -92,7 +88,7 @@ def _plain(self, hash_value: str, password: str) -> bool:
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())
Expand Down

0 comments on commit dfaef5d

Please sign in to comment.