mirror of
https://github.com/django/django.git
synced 2025-11-19 03:08:59 +00:00
Merge c8a756ca3e into 1ce6e78dd4
This commit is contained in:
commit
efac773d78
2 changed files with 19 additions and 2 deletions
|
|
@ -569,8 +569,11 @@ class BCryptPasswordHasher(BCryptSHA256PasswordHasher):
|
||||||
issues.
|
issues.
|
||||||
|
|
||||||
This hasher does not first hash the password which means it is subject to
|
This hasher does not first hash the password which means it is subject to
|
||||||
bcrypt's 72 bytes password truncation. Most use cases should prefer the
|
bcrypt's 72 byte limit. With bcrypt version 5 or newer, a `ValueError`
|
||||||
BCryptSHA256PasswordHasher.
|
will be raised if the password exceeds 72 bytes. On older versions, the
|
||||||
|
password is silently truncated to 72 characters.
|
||||||
|
|
||||||
|
The BCryptSHA256PasswordHasher won't raise exceptions on longer passwords.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
algorithm = "bcrypt"
|
algorithm = "bcrypt"
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,20 @@ class TestUtilsHashPass(SimpleTestCase):
|
||||||
self.assertTrue(check_password("", blank_encoded))
|
self.assertTrue(check_password("", blank_encoded))
|
||||||
self.assertFalse(check_password(" ", blank_encoded))
|
self.assertFalse(check_password(" ", blank_encoded))
|
||||||
|
|
||||||
|
@skipUnless(bcrypt, "bcrypt not installed")
|
||||||
|
@override_settings(
|
||||||
|
PASSWORD_HASHERS=["django.contrib.auth.hashers.BCryptPasswordHasher"]
|
||||||
|
)
|
||||||
|
def test_bcrypt_truncation(self):
|
||||||
|
if bcrypt.__version__ >= "5.0.0":
|
||||||
|
with self.assertRaises(ValueError) as cm:
|
||||||
|
encoded = make_password(73 * "x", hasher="bcrypt")
|
||||||
|
self.assertIn("72 bytes", str(cm.exception))
|
||||||
|
else:
|
||||||
|
# Older versions silently truncated to 72 bytes
|
||||||
|
encoded = make_password(73 * "x", hasher="bcrypt")
|
||||||
|
self.assertTrue(check_password(72 * "x", encoded))
|
||||||
|
|
||||||
@skipUnless(bcrypt, "bcrypt not installed")
|
@skipUnless(bcrypt, "bcrypt not installed")
|
||||||
@override_settings(
|
@override_settings(
|
||||||
PASSWORD_HASHERS=["django.contrib.auth.hashers.BCryptPasswordHasher"]
|
PASSWORD_HASHERS=["django.contrib.auth.hashers.BCryptPasswordHasher"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue