authenticate user after their reset confirmation goes through

make password validation code more DRY

grammar nit: "less" -> "fewer"
This commit is contained in:
Adam Palay
2016-06-10 11:21:55 -04:00
parent 5ba8cf8324
commit 95c0b50ebe
6 changed files with 200 additions and 170 deletions

View File

@@ -15,6 +15,26 @@ from django.conf import settings
import nltk
def validate_password_strength(value):
"""
This function loops through each validator defined in this file
and applies it to a user's proposed password
Args:
value: a user's proposed password
Returns: None, but raises a ValidationError if the proposed password
fails any one of the validators in password_validators
"""
password_validators = [
validate_password_length,
validate_password_complexity,
validate_password_dictionary,
]
for validator in password_validators:
validator(value)
def validate_password_length(value):
"""
Validator that enforces minimum length of a password
@@ -28,7 +48,7 @@ def validate_password_length(value):
if min_length and len(value) < min_length:
raise ValidationError(message.format(_("must be {0} characters or more").format(min_length)), code=code)
elif max_length and len(value) > max_length:
raise ValidationError(message.format(_("must be {0} characters or less").format(max_length)), code=code)
raise ValidationError(message.format(_("must be {0} characters or fewer").format(max_length)), code=code)
def validate_password_complexity(value):