From 4aed731154b12e2948ee2b6a8baa5083840a343b Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Sat, 3 Jan 2015 13:36:13 -0500 Subject: [PATCH] [1.7.x] Increased the default PBKDF2 iterations. --- django/contrib/auth/hashers.py | 4 ++-- django/contrib/auth/tests/test_hashers.py | 6 +++--- docs/releases/1.7.3.txt | 7 ++++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/django/contrib/auth/hashers.py b/django/contrib/auth/hashers.py index 4e40a7c2ba..e459f3990e 100644 --- a/django/contrib/auth/hashers.py +++ b/django/contrib/auth/hashers.py @@ -222,12 +222,12 @@ class PBKDF2PasswordHasher(BasePasswordHasher): """ Secure password hashing using the PBKDF2 algorithm (recommended) - Configured to use PBKDF2 + HMAC + SHA256 with 12000 iterations. + Configured to use PBKDF2 + HMAC + SHA256 with 15000 iterations. The result is a 64 byte binary string. Iterations may be changed safely but you must rename the algorithm if you change SHA256. """ algorithm = "pbkdf2_sha256" - iterations = 12000 + iterations = 15000 digest = hashlib.sha256 def encode(self, password, salt, iterations=None): diff --git a/django/contrib/auth/tests/test_hashers.py b/django/contrib/auth/tests/test_hashers.py index 58628cd6cd..85f1c15b53 100644 --- a/django/contrib/auth/tests/test_hashers.py +++ b/django/contrib/auth/tests/test_hashers.py @@ -47,7 +47,7 @@ class TestUtilsHashPass(SimpleTestCase): def test_pkbdf2(self): encoded = make_password('lètmein', 'seasalt', 'pbkdf2_sha256') self.assertEqual(encoded, - 'pbkdf2_sha256$12000$seasalt$Ybw8zsFxqja97tY/o6G+Fy1ksY4U/Hw3DRrGED6Up4s=') + 'pbkdf2_sha256$15000$seasalt$+qoFTwR4r71UCLMhmQUCou/LMu17XwQWfYIVd/xJ1RI=') self.assertTrue(is_password_usable(encoded)) self.assertTrue(check_password('lètmein', encoded)) self.assertFalse(check_password('lètmeinz', encoded)) @@ -211,14 +211,14 @@ class TestUtilsHashPass(SimpleTestCase): hasher = PBKDF2PasswordHasher() encoded = hasher.encode('lètmein', 'seasalt2') self.assertEqual(encoded, - 'pbkdf2_sha256$12000$seasalt2$hlDLKsxgkgb1aeOppkM5atCYw5rPzAjCNQZ4NYyUROw=') + 'pbkdf2_sha256$15000$seasalt2$uSQqI+91wgObKdP6L6S75LLzyxrZRWNcaujEZPA3/nA=') self.assertTrue(hasher.verify('lètmein', encoded)) def test_low_level_pbkdf2_sha1(self): hasher = PBKDF2SHA1PasswordHasher() encoded = hasher.encode('lètmein', 'seasalt2') self.assertEqual(encoded, - 'pbkdf2_sha1$12000$seasalt2$JeMRVfjjgtWw3/HzlnlfqBnQ6CA=') + 'pbkdf2_sha1$15000$seasalt2$iYDXAPKgMsKMsarvA1MErD518Ug=') self.assertTrue(hasher.verify('lètmein', encoded)) def test_upgrade(self): diff --git a/docs/releases/1.7.3.txt b/docs/releases/1.7.3.txt index 6eb8194ba0..50b6b18f16 100644 --- a/docs/releases/1.7.3.txt +++ b/docs/releases/1.7.3.txt @@ -11,4 +11,9 @@ Django 1.7.3 fixes several bugs in 1.7.2. Bugfixes ======== -* ... +* The default iteration count for the PBKDF2 password hasher has been + increased by 25%. This part of the normal major release process was + inadvertently omitted in 1.7. This backwards compatible change will not + affect users who have subclassed + ``django.contrib.auth.hashers.PBKDF2PasswordHasher`` to change the + default value.