changeset 6324:97619528c270

auth: remove KallitheaCrypto pseudo-class Every caller except one already used the module-level wrapper functions.
author Søren Løvborg <sorenl@unity3d.com>
date Wed, 09 Nov 2016 15:49:49 +0100
parents 533ec10dfd59
children aa2542a6538b
files kallithea/lib/auth.py kallithea/lib/auth_modules/auth_internal.py
diffstat 2 files changed, 30 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/auth.py	Mon Oct 10 23:15:05 2016 +0200
+++ b/kallithea/lib/auth.py	Wed Nov 09 15:49:49 2016 +0100
@@ -94,52 +94,40 @@
         return ''.join(l)
 
 
-class KallitheaCrypto(object):
-
-    @classmethod
-    def hash_string(cls, str_):
-        """
-        Cryptographic function used for password hashing based on pybcrypt
-        or Python's own OpenSSL wrapper on windows
-
-        :param password: password to hash
-        """
-        if is_windows:
-            return hashlib.sha256(str_).hexdigest()
-        elif is_unix:
-            import bcrypt
-            return bcrypt.hashpw(safe_str(str_), bcrypt.gensalt(10))
-        else:
-            raise Exception('Unknown or unsupported platform %s' \
-                            % __platform__)
+def get_crypt_password(password):
+    """
+    Cryptographic function used for password hashing based on pybcrypt
+    or Python's own OpenSSL wrapper on windows
 
-    @classmethod
-    def hash_check(cls, password, hashed):
-        """
-        Checks matching password with it's hashed value, runs different
-        implementation based on platform it runs on
-
-        :param password: password
-        :param hashed: password in hashed form
-        """
-
-        if is_windows:
-            return hashlib.sha256(password).hexdigest() == hashed
-        elif is_unix:
-            import bcrypt
-            return bcrypt.checkpw(safe_str(password), safe_str(hashed))
-        else:
-            raise Exception('Unknown or unsupported platform %s' \
-                            % __platform__)
-
-
-def get_crypt_password(password):
-    return KallitheaCrypto.hash_string(password)
+    :param password: password to hash
+    """
+    if is_windows:
+        return hashlib.sha256(password).hexdigest()
+    elif is_unix:
+        import bcrypt
+        return bcrypt.hashpw(safe_str(password), bcrypt.gensalt(10))
+    else:
+        raise Exception('Unknown or unsupported platform %s' \
+                        % __platform__)
 
 
 def check_password(password, hashed):
-    return KallitheaCrypto.hash_check(password, hashed)
+    """
+    Checks matching password with it's hashed value, runs different
+    implementation based on platform it runs on
+
+    :param password: password
+    :param hashed: password in hashed form
+    """
 
+    if is_windows:
+        return hashlib.sha256(password).hexdigest() == hashed
+    elif is_unix:
+        import bcrypt
+        return bcrypt.checkpw(safe_str(password), safe_str(hashed))
+    else:
+        raise Exception('Unknown or unsupported platform %s' \
+                        % __platform__)
 
 
 def _cached_perms_data(user_id, user_is_admin, user_inherit_default_permissions,
--- a/kallithea/lib/auth_modules/auth_internal.py	Mon Oct 10 23:15:05 2016 +0200
+++ b/kallithea/lib/auth_modules/auth_internal.py	Wed Nov 09 15:49:49 2016 +0100
@@ -86,7 +86,7 @@
         log.debug(formatted_json(user_data))
         if userobj.active:
             from kallithea.lib import auth
-            password_match = auth.KallitheaCrypto.hash_check(password, userobj.password)
+            password_match = auth.check_password(password, userobj.password)
             if userobj.username == User.DEFAULT_USER and userobj.active:
                 log.info('user %s authenticated correctly as anonymous user',
                          username)