From 9af15e6656f3fb28916726e4be419a798d80d078 Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Mon, 30 Dec 2024 05:25:10 +0100 Subject: [PATCH] fixes triggered by tox --- radicale/auth/__init__.py | 6 +++--- radicale/auth/htpasswd.py | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/radicale/auth/__init__.py b/radicale/auth/__init__.py index 9cb70bb8..39e07026 100644 --- a/radicale/auth/__init__.py +++ b/radicale/auth/__init__.py @@ -96,7 +96,7 @@ class BaseAuth: h.update(salt.encode()) h.update(login.encode()) h.update(password.encode()) - return h.digest() + return str(h.digest()) def get_external_login(self, environ: types.WSGIEnviron) -> Union[ Tuple[()], Tuple[str, str]]: @@ -155,8 +155,8 @@ class BaseAuth: digest = self._cache_digest(login, password, str(time_ns)) if result == "": result = self._login(login, password) - if result is not "": - if digest is "": + if result != "": + if digest == "": # successful login, but expired, digest must be recalculated digest = self._cache_digest(login, password, str(time_ns)) # store successful login in cache diff --git a/radicale/auth/htpasswd.py b/radicale/auth/htpasswd.py index 43fee1b9..1767c9e1 100644 --- a/radicale/auth/htpasswd.py +++ b/radicale/auth/htpasswd.py @@ -94,23 +94,23 @@ class Auth(auth.BaseAuth): raise RuntimeError("The htpasswd encryption method %r is not " "supported." % encryption) - def _plain(self, hash_value: str, password: str) -> bool: + def _plain(self, hash_value: str, password: str) -> tuple[str, bool]: """Check if ``hash_value`` and ``password`` match, plain method.""" return ("PLAIN", hmac.compare_digest(hash_value.encode(), password.encode())) - def _bcrypt(self, bcrypt: Any, hash_value: str, password: str) -> bool: + def _bcrypt(self, bcrypt: Any, hash_value: str, password: str) -> tuple[str, bool]: return ("BCRYPT", bcrypt.checkpw(password=password.encode('utf-8'), hashed_password=hash_value.encode())) - def _md5apr1(self, hash_value: str, password: str) -> bool: + def _md5apr1(self, hash_value: str, password: str) -> tuple[str, bool]: return ("MD5-APR1", apr_md5_crypt.verify(password, hash_value.strip())) - def _sha256(self, hash_value: str, password: str) -> bool: + def _sha256(self, hash_value: str, password: str) -> tuple[str, bool]: return ("SHA-256", sha256_crypt.verify(password, hash_value.strip())) - def _sha512(self, hash_value: str, password: str) -> bool: + def _sha512(self, hash_value: str, password: str) -> tuple[str, bool]: return ("SHA-512", sha512_crypt.verify(password, hash_value.strip())) - def _autodetect(self, hash_value: str, password: str) -> bool: + def _autodetect(self, hash_value: str, password: str) -> tuple[str, bool]: if hash_value.startswith("$apr1$", 0, 6) and len(hash_value) == 37: # MD5-APR1 return self._md5apr1(hash_value, password)