Skip to content

Instantly share code, notes, and snippets.

@pfreixes
Created August 7, 2013 08:57
Show Gist options
  • Save pfreixes/6172406 to your computer and use it in GitHub Desktop.
Save pfreixes/6172406 to your computer and use it in GitHub Desktop.
One no CPU BOUND Django Hasher to avoid long time tests......
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