Created
July 16, 2019 14:12
-
-
Save mblayman/a9ca4f176bcfaa999ecdba8bfa01a99e to your computer and use it in GitHub Desktop.
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 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