Created
August 7, 2013 08:57
-
-
Save pfreixes/6172406 to your computer and use it in GitHub Desktop.
One no CPU BOUND Django Hasher to avoid long time tests......
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.hashers import BasePasswordHasher | |
class TestPasswordHasher(BasePasswordHasher): | |
""" | |
Just for testing propuses to be used in test environments | |
and avoid CPU BOUND operations by current installed | |
pasword hashers. | |
""" | |
algorithm = "test" | |
def salt(self): | |
return '' | |
def encode(self, password, salt): | |
assert salt == '' | |
return '%s$%s' % (TestPasswordHasher.algorithm, password) | |
def verify(self, password, encoded): | |
encoded_2 = self.encode(password, '') | |
return (encoded == encoded_2) | |
def safe_summary(self, encoded): | |
assert encoded.startswith('%s$') % TestPasswordHasher.algorithm | |
hash = encoded[6:] | |
return SortedDict([ | |
(_('algorithm'), self.algorithm), | |
(_('hash'), mask_hash(hash)), | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment