Commit 08a8afa6 by David Baumgold

For methods on PasswordHistory, only calculate if necessary

Check settings.FEATURES["ADVANCED_SECURITY"] first
parent 4fcf1f9e
...@@ -452,50 +452,60 @@ class PasswordHistory(models.Model): ...@@ -452,50 +452,60 @@ class PasswordHistory(models.Model):
""" """
Returns whether the configuration which limits password reuse has been turned on 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_diff_pw = settings.ADVANCED_SECURITY_CONFIG.get(
'MIN_DIFFERENT_STUDENT_PASSWORDS_BEFORE_REUSE', 0 'MIN_DIFFERENT_STUDENT_PASSWORDS_BEFORE_REUSE', 0
) )
return settings.FEATURES['ADVANCED_SECURITY'] and min_diff_pw > 0 return min_diff_pw > 0
@classmethod @classmethod
def is_staff_password_reuse_restricted(cls): def is_staff_password_reuse_restricted(cls):
""" """
Returns whether the configuration which limits password reuse has been turned on 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_diff_pw = settings.ADVANCED_SECURITY_CONFIG.get(
'MIN_DIFFERENT_STAFF_PASSWORDS_BEFORE_REUSE', 0 'MIN_DIFFERENT_STAFF_PASSWORDS_BEFORE_REUSE', 0
) )
return settings.FEATURES['ADVANCED_SECURITY'] and min_diff_pw > 0 return min_diff_pw > 0
@classmethod @classmethod
def is_password_reset_frequency_restricted(cls): def is_password_reset_frequency_restricted(cls):
""" """
Returns whether the configuration which limits the password reset frequency has been turned on 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_days_between_reset = settings.ADVANCED_SECURITY_CONFIG.get(
'MIN_TIME_IN_DAYS_BETWEEN_ALLOWED_RESETS' 'MIN_TIME_IN_DAYS_BETWEEN_ALLOWED_RESETS'
) )
return settings.FEATURES['ADVANCED_SECURITY'] and min_days_between_reset return min_days_between_reset
@classmethod @classmethod
def is_staff_forced_password_reset_enabled(cls): def is_staff_forced_password_reset_enabled(cls):
""" """
Returns whether the configuration which forces password resets to occur has been turned on 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_between_reset = settings.ADVANCED_SECURITY_CONFIG.get(
'MIN_DAYS_FOR_STAFF_ACCOUNTS_PASSWORD_RESETS' 'MIN_DAYS_FOR_STAFF_ACCOUNTS_PASSWORD_RESETS'
) )
return settings.FEATURES['ADVANCED_SECURITY'] and min_days_between_reset return min_days_between_reset
@classmethod @classmethod
def is_student_forced_password_reset_enabled(cls): def is_student_forced_password_reset_enabled(cls):
""" """
Returns whether the configuration which forces password resets to occur has been turned on 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_pw_reset = settings.ADVANCED_SECURITY_CONFIG.get(
'MIN_DAYS_FOR_STUDENT_ACCOUNTS_PASSWORD_RESETS' 'MIN_DAYS_FOR_STUDENT_ACCOUNTS_PASSWORD_RESETS'
) )
return settings.FEATURES['ADVANCED_SECURITY'] and min_days_pw_reset return min_days_pw_reset
@classmethod @classmethod
def should_user_reset_password_now(cls, user): def should_user_reset_password_now(cls, user):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment