Skip to content

Instantly share code, notes, and snippets.

@nmariz
Forked from dcramer/django_bcrypt_legacy.py
Created September 2, 2013 15:52
Show Gist options
  • Save nmariz/6414369 to your computer and use it in GitHub Desktop.
Save nmariz/6414369 to your computer and use it in GitHub Desktop.
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