Work around Py32's hashib nannyism.
| | |
| | | except UnicodeDecodeError: |
| | | return value.decode('latin1') |
| | | return value |
| | | |
| | | def must_encode(value): |
| | | if type(value) is u: |
| | | return value.encode('utf-8') |
| | | return value |
| | |
| | | |
| | | def sha1_check(password, hashed): |
| | | from hashlib import sha1 |
| | | import base64 |
| | | encrypted_string = base64.standard_b64encode(sha1(password).digest()) |
| | | from base64 import standard_b64encode |
| | | from repoze.who._compat import must_encode |
| | | encrypted_string = standard_b64encode(sha1(must_encode(password)).digest()) |
| | | return _same_string(hashed, "%s%s" % ("{SHA}", encrypted_string)) |
| | | |
| | | def plain_check(password, hashed): |
| | |
| | | self.assertEqual(crypt_check('notpassword', hashed), False) |
| | | |
| | | def test_sha1_check(self): |
| | | import base64 |
| | | from base64 import standard_b64encode |
| | | from hashlib import sha1 |
| | | from repoze.who._compat import must_encode |
| | | from repoze.who.plugins.htpasswd import sha1_check |
| | | |
| | | encrypted_string = base64.standard_b64encode(sha1("password").digest()) |
| | | encrypted_string = standard_b64encode(sha1( |
| | | must_encode("password")).digest()) |
| | | self.assertEqual(sha1_check('password', |
| | | "%s%s" % ("{SHA}",encrypted_string)), True) |
| | | "%s%s" % ("{SHA}", encrypted_string)), True) |
| | | self.assertEqual(sha1_check('notpassword', |
| | | "%s%s" % ("{SHA}", encrypted_string)), False) |
| | | |