Skip to content

Commit

Permalink
Increased the default PBKDF2 iterations for Django 5.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
nessita committed May 22, 2024
1 parent fdfeff8 commit d644abe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion django/contrib/auth/hashers.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class PBKDF2PasswordHasher(BasePasswordHasher):
"""

algorithm = "pbkdf2_sha256"
iterations = 870000
iterations = 1_000_000
digest = hashlib.sha256

def encode(self, password, salt, iterations=None):
Expand Down
3 changes: 2 additions & 1 deletion docs/releases/5.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Minor features
:mod:`django.contrib.auth`
~~~~~~~~~~~~~~~~~~~~~~~~~~

* ...
* The default iteration count for the PBKDF2 password hasher is increased from
870,000 to 1,000,000.

:mod:`django.contrib.contenttypes`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
9 changes: 5 additions & 4 deletions tests/auth_tests/test_hashers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def test_pbkdf2(self):
encoded = make_password("lètmein", "seasalt", "pbkdf2_sha256")
self.assertEqual(
encoded,
"pbkdf2_sha256$870000$seasalt$wJSpLMQRQz0Dhj/pFpbyjMj71B2gUYp6HJS5AU+32Ac=",
"pbkdf2_sha256$1000000$"
"seasalt$r1uLUxoxpP2Ued/qxvmje7UH9PUJBkRrvf9gGPL7Cps=",
)
self.assertTrue(is_password_usable(encoded))
self.assertTrue(check_password("lètmein", encoded))
Expand Down Expand Up @@ -276,16 +277,16 @@ def test_low_level_pbkdf2(self):
encoded = hasher.encode("lètmein", "seasalt2")
self.assertEqual(
encoded,
"pbkdf2_sha256$870000$"
"seasalt2$nxgnNHRsZWSmi4hRSKq2MRigfaRmjDhH1NH4g2sQRbU=",
"pbkdf2_sha256$1000000$"
"seasalt2$egbhFghgsJVDo5Tpg/k9ZnfbySKQ1UQnBYXhR97a7sk=",
)
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$870000$seasalt2$iFPKnrkYfxxyxaeIqxq+c3nJ/j4="
encoded, "pbkdf2_sha1$1000000$seasalt2$3R9hvSAiAy5ARspAFy5GJ/2rjXo="
)
self.assertTrue(hasher.verify("lètmein", encoded))

Expand Down

0 comments on commit d644abe

Please sign in to comment.