Skip to content

Instantly share code, notes, and snippets.

@mblayman
Created July 16, 2019 14:12
Show Gist options
  • Save mblayman/a9ca4f176bcfaa999ecdba8bfa01a99e to your computer and use it in GitHub Desktop.
Save mblayman/a9ca4f176bcfaa999ecdba8bfa01a99e to your computer and use it in GitHub Desktop.
from django.contrib.auth.hashers import BasePasswordHasher
class SimplePasswordHasher(BasePasswordHasher):
"""A simple hasher inspired by django-plainpasswordhasher to save test
execution time
"""
algorithm = 'dumb' # This attribute is needed by the base class.
def salt(self):
return ''
def encode(self, password, salt):
return 'dumb$$%s' % password
def verify(self, password, encoded):
algorithm, hash = encoded.split('$$', 1)
assert algorithm == 'dumb'
return password == hash
def safe_summary(self, encoded):
"""This is a decidedly unsafe version. The password is returned in the
clear."""
return {
'algorithm': 'dumb',
'hash': encoded.split('$', 2)[2]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment