Ticket #18182: 18182-2.diff

File 18182-2.diff, 1.2 KB (added by Claude Paroz, 12 years ago)

Updated and using identify_hasher

  • django/contrib/auth/hashers.py

    diff --git a/django/contrib/auth/hashers.py b/django/contrib/auth/hashers.py
    index 96ec40b..18a11a4 100644
    a b def reset_hashers(**kwargs):  
    2727
    2828
    2929def is_password_usable(encoded):
    30     return (encoded is not None and encoded != UNUSABLE_PASSWORD)
     30    if encoded is None or encoded == UNUSABLE_PASSWORD:
     31        return False
     32    try:
     33        hasher = identify_hasher(encoded)
     34    except ValueError:
     35        return False
     36    return True
    3137
    3238
    3339def check_password(password, encoded, setter=None, preferred='default'):
  • django/contrib/auth/tests/hashers.py

    diff --git a/django/contrib/auth/tests/hashers.py b/django/contrib/auth/tests/hashers.py
    index 673263b..cb9d97d 100644
    a b class TestUtilsHashPass(unittest.TestCase):  
    100100        self.assertRaises(ValueError, doit)
    101101        self.assertRaises(ValueError, identify_hasher, "lolcat$salt$hash")
    102102
     103    def test_bad_encoded(self):
     104        encoded = 'letmein_badencoded'
     105        self.assertFalse(is_password_usable(encoded))
     106
    103107    def test_low_level_pkbdf2(self):
    104108        hasher = PBKDF2PasswordHasher()
    105109        encoded = hasher.encode('letmein', 'seasalt')
Back to Top