Created
May 7, 2013 15:36
-
-
Save dcramer/5533572 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 BCryptPasswordHasher | |
from django.utils.crypto import constant_time_compare | |
from django.utils.encoding import force_bytes | |
class DjangoBCryptPasswordHasher(BCryptPasswordHasher): | |
""" | |
Handles legacy passwords wich were hashed with the 'bc$' algorithm via | |
django-bcrypt. | |
""" | |
algorithm = "bc" | |
def verify(self, password, encoded): | |
data = encoded[3:] | |
bcrypt = self._load_library() | |
return constant_time_compare(data, bcrypt.hashpw(force_bytes(password), data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment