# HG changeset patch # User Søren Løvborg # Date 1478702989 -3600 # Node ID 97619528c270c81f7fca3e00ccfc2d58f7143afe # Parent 533ec10dfd59a032a5240f93868a8e889fba4611 auth: remove KallitheaCrypto pseudo-class Every caller except one already used the module-level wrapper functions. diff -r 533ec10dfd59 -r 97619528c270 kallithea/lib/auth.py --- 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, diff -r 533ec10dfd59 -r 97619528c270 kallithea/lib/auth_modules/auth_internal.py --- 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)