From 08a8afa61950bd002b53aab9c2ef17683e56f1a6 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Fri, 12 Dec 2014 11:52:59 -0500 Subject: [PATCH] For methods on PasswordHistory, only calculate if necessary Check settings.FEATURES["ADVANCED_SECURITY"] first --- common/djangoapps/student/models.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index a85caeda08..01d48b8425 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -452,50 +452,60 @@ class PasswordHistory(models.Model): """ Returns whether the configuration which limits password reuse has been turned on """ + if not settings.FEATURES['ADVANCED_SECURITY']: + return False min_diff_pw = settings.ADVANCED_SECURITY_CONFIG.get( 'MIN_DIFFERENT_STUDENT_PASSWORDS_BEFORE_REUSE', 0 ) - return settings.FEATURES['ADVANCED_SECURITY'] and min_diff_pw > 0 + return min_diff_pw > 0 @classmethod def is_staff_password_reuse_restricted(cls): """ Returns whether the configuration which limits password reuse has been turned on """ + if not settings.FEATURES['ADVANCED_SECURITY']: + return False min_diff_pw = settings.ADVANCED_SECURITY_CONFIG.get( 'MIN_DIFFERENT_STAFF_PASSWORDS_BEFORE_REUSE', 0 ) - return settings.FEATURES['ADVANCED_SECURITY'] and min_diff_pw > 0 + return min_diff_pw > 0 @classmethod def is_password_reset_frequency_restricted(cls): """ Returns whether the configuration which limits the password reset frequency has been turned on """ + if not settings.FEATURES['ADVANCED_SECURITY']: + return False min_days_between_reset = settings.ADVANCED_SECURITY_CONFIG.get( 'MIN_TIME_IN_DAYS_BETWEEN_ALLOWED_RESETS' ) - return settings.FEATURES['ADVANCED_SECURITY'] and min_days_between_reset + return min_days_between_reset @classmethod def is_staff_forced_password_reset_enabled(cls): """ Returns whether the configuration which forces password resets to occur has been turned on """ + if not settings.FEATURES['ADVANCED_SECURITY']: + return False min_days_between_reset = settings.ADVANCED_SECURITY_CONFIG.get( 'MIN_DAYS_FOR_STAFF_ACCOUNTS_PASSWORD_RESETS' ) - return settings.FEATURES['ADVANCED_SECURITY'] and min_days_between_reset + return min_days_between_reset @classmethod def is_student_forced_password_reset_enabled(cls): """ Returns whether the configuration which forces password resets to occur has been turned on """ + if not settings.FEATURES['ADVANCED_SECURITY']: + return False min_days_pw_reset = settings.ADVANCED_SECURITY_CONFIG.get( 'MIN_DAYS_FOR_STUDENT_ACCOUNTS_PASSWORD_RESETS' ) - return settings.FEATURES['ADVANCED_SECURITY'] and min_days_pw_reset + return min_days_pw_reset @classmethod def should_user_reset_password_now(cls, user):