Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.4.x] Fixed #18144 -- Added backwards compatibility with old unsalt…

…ed MD5 passwords

Thanks apreobrazhensky at gmail.com for the report.
Backport of 63d6a50 from master.
  • Loading branch information...
commit 6bd3896fcb5c626a5ef613895d52c69130156d3a 1 parent 89ba1b2
@claudep claudep authored
View
5 django/contrib/auth/hashers.py
@@ -35,7 +35,8 @@ def check_password(password, encoded, setter=None, preferred='default'):
password = smart_str(password)
encoded = smart_str(encoded)
- if len(encoded) == 32 and '$' not in encoded:
+ if ((len(encoded) == 32 and '$' not in encoded) or
+ (len(encoded) == 37 and encoded.startswith('md5$$'))):
hasher = get_hasher('unsalted_md5')
else:
algorithm = encoded.split('$', 1)[0]
@@ -347,6 +348,8 @@ def encode(self, password, salt):
return hashlib.md5(password).hexdigest()
def verify(self, password, encoded):
+ if len(encoded) == 37 and encoded.startswith('md5$$'):
+ encoded = encoded[5:]
encoded_2 = self.encode(password, '')
return constant_time_compare(encoded, encoded_2)
View
5 django/contrib/auth/tests/hashers.py
@@ -59,6 +59,11 @@ def test_unsalted_md5(self):
self.assertTrue(is_password_usable(encoded))
self.assertTrue(check_password(u'letmein', encoded))
self.assertFalse(check_password('letmeinz', encoded))
+ # Alternate unsalted syntax
+ alt_encoded = "md5$$%s" % encoded
+ self.assertTrue(is_password_usable(alt_encoded))
+ self.assertTrue(check_password(u'letmein', alt_encoded))
+ self.assertFalse(check_password('letmeinz', alt_encoded))
@skipUnless(crypt, "no crypt module to generate password.")
def test_crypt(self):
Please sign in to comment.
Something went wrong with that request. Please try again.