Skip to content
Snippets Groups Projects
Commit a5f3f1cb authored by Dillon Dumesnil's avatar Dillon Dumesnil
Browse files

Ensuring password to be normalized is unicode

parent 3619ec0d
No related merge requests found
......@@ -91,9 +91,17 @@ def password_validators_restrictions():
def normalize_password(password):
"""
Converts the password to utf-8 if it is not unicode already.
Normalize all passwords to 'NFKC' across the platform to prevent mismatched hash strings when comparing entered
passwords on login. See LEARNER-4283 for more context.
"""
if not isinstance(password, text_type):
try:
# some checks rely on unicode semantics (e.g. length)
password = text_type(password, encoding='utf8')
except UnicodeDecodeError:
# no reason to get into weeds
raise ValidationError([_('Invalid password.')])
return unicodedata.normalize('NFKC', password)
......@@ -101,7 +109,7 @@ def validate_password(password, user=None):
"""
EdX's custom password validator for passwords. This function performs the
following functions:
1) Converts the password to unicode if it is not already
1) Normalizes the password according to NFKC unicode standard
2) Calls Django's validate_password method. This calls the validate function
in all validators specified in AUTH_PASSWORD_VALIDATORS configuration.
......@@ -114,8 +122,7 @@ def validate_password(password, user=None):
None
Raises:
ValidationError if unable to convert password to utf8 or if any of the
password validators fail.
ValidationError if any of the password validators fail.
"""
if not isinstance(password, text_type):
try:
......
"""
Utility methods for the account settings.
"""
from __future__ import unicode_literals
import random
import re
import string
......
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