diff options
| author | Mateo Radman <48420316+mateoradman@users.noreply.github.com> | 2021-09-05 17:24:09 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-09-06 07:47:53 +0200 |
| commit | a7f27fca5239ff3840735dc6dc731b71a99a1d57 (patch) | |
| tree | 64e1b9800f4f717c6f70ef9efaccba19bf58bd3a /django | |
| parent | e75a3a770e5da8af3405be1e216a6c20cc9bde5a (diff) | |
Refs #32508 -- Raised TypeError/ValueError instead of using "assert" in encode() methods of remaining password hashers.
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/auth/hashers.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/django/contrib/auth/hashers.py b/django/contrib/auth/hashers.py index 9946014ad2..cac11dfd4c 100644 --- a/django/contrib/auth/hashers.py +++ b/django/contrib/auth/hashers.py @@ -689,7 +689,8 @@ class UnsaltedSHA1PasswordHasher(BasePasswordHasher): return '' def encode(self, password, salt): - assert salt == '' + if salt != '': + raise ValueError('salt must be empty.') hash = hashlib.sha1(password.encode()).hexdigest() return 'sha1$$%s' % hash @@ -733,7 +734,8 @@ class UnsaltedMD5PasswordHasher(BasePasswordHasher): return '' def encode(self, password, salt): - assert salt == '' + if salt != '': + raise ValueError('salt must be empty.') return hashlib.md5(password.encode()).hexdigest() def decode(self, encoded): @@ -774,9 +776,11 @@ class CryptPasswordHasher(BasePasswordHasher): def encode(self, password, salt): crypt = self._load_library() - assert len(salt) == 2 + if len(salt) != 2: + raise ValueError('salt must be of length 2.') hash = crypt.crypt(password, salt) - assert hash is not None # A platform like OpenBSD with a dummy crypt module. + if hash is None: # A platform like OpenBSD with a dummy crypt module. + raise TypeError('hash must be provided.') # we don't need to store the salt, but Django used to do this return '%s$%s$%s' % (self.algorithm, '', hash) |
