From b1ac289ee8ed20b5548a46db9e2d8ca3eb66de71 Mon Sep 17 00:00:00 2001 From: Philipp Spitzer Date: Tue, 29 Sep 2020 21:45:16 +0200 Subject: [PATCH] PEP8 improvements. --- wradmin/auth/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/wradmin/auth/__init__.py b/wradmin/auth/__init__.py index 80ab396..f0e6907 100644 --- a/wradmin/auth/__init__.py +++ b/wradmin/auth/__init__.py @@ -6,7 +6,10 @@ def password_is_correct(password_plain, password_db): """Returns true if a plain text password corresponds to the hash of the password as stored in the MediaWiki db. :param password_plain: plain text password as string, e.g. 'abc' - :param password_db: complete password line as string as stored in the database, e.g. ':pbkdf2:sha256:10000:128:EXgVGhc2mAs710feKvkiaw==:J5fYth9pg/R2d0F8bSsYfTR8SBpTBNIcdv/DgJ0tOPC1rtajl2Dr0RLqOozLb8O0XpDhtv4a3JJd/M0b58WebfNWAcdJBJI9nNeC0EYYD7OCYZGVAaRhiYtK4m53KZBBL6x/k2j4RjHPT1NmgV8Fr1DPqBNOlOHxUIh5z5oslM4=' + :param password_db: complete password line as string as stored in the database, + e.g. ':pbkdf2:sha256:10000:128:EXgVGhc2mAs710feKvkiaw==:J5fYth9pg/R2d0F8bSsYfTR8SBpTBNIcdv/DgJ0tOPC' + + '1rtajl2Dr0RLqOozLb8O0XpDhtv4a3JJd/M0b58WebfNWAcdJBJI9nNeC0EYYD7OCYZGVAaRhiYtK4m53KZBBL6x/k2j4' + + 'RjHPT1NmgV8Fr1DPqBNOlOHxUIh5z5oslM4=' """ if not password_db.startswith(':'): raise ValueError("Password entry in the database does have an unexpected format (does not start with ':').") @@ -19,7 +22,8 @@ def password_is_correct(password_plain, password_db): if len(pwd_parts) != 3: raise ValueError("Password entry in the database does have an unexpected format (too few ':').") salt, pwd_md5 = tuple(pwd_parts[1:3]) # salt = 'd25b2886'; pwd_md5 = '41e46c952790b1b442aac4f24f7ea7a8' - # log.info("user: '%s'; md5 of salt+' '+entered_pwd: '%s'; md5-part of DB-pwd: %s" % (username, md5(salt + '-' + md5(password)), pwd_md5)) + # log.info("user: '%s'; md5 of salt+' '+entered_pwd: '%s'; md5-part of DB-pwd: %s" + # % (username, md5(salt + '-' + md5(password)), pwd_md5)) salt_and_plain = salt + '-' + md5(password_plain.encode()).hexdigest() return md5(salt_and_plain.encode()).hexdigest() == pwd_md5 elif pwd_type == 'pbkdf2': @@ -27,8 +31,8 @@ def password_is_correct(password_plain, password_db): raise ValueError("Password entry in the database does have an unexpected format (too few ':').") _, algorithm, rounds, num_bit, salt, pwd_hash = pwd_parts salt = b64decode(salt) - hash = pbkdf2_hmac(algorithm, password_plain.encode(), salt, int(rounds), int(num_bit)) - hash = b64encode(hash).decode() - return hash == pwd_hash + hashcode = pbkdf2_hmac(algorithm, password_plain.encode(), salt, int(rounds), int(num_bit)) + hashcode = b64encode(hashcode).decode() + return hashcode == pwd_hash else: raise ValueError("Unknown password type") -- 2.39.5