Created
February 18, 2017 09:43
-
-
Save Beomi/54754a09fd95195d6cd9e14b75126d92 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
class MyUserAuthBackend(object): | |
def check_legacy_password(self, db_password, supplied_password): | |
return constant_time_compare('*'+ hashlib.sha1(hashlib.sha1(supplied_password.encode('utf-8')).digest()).hexdigest().upper(), db_password) | |
def authenticate(self, username=None, password=None): | |
""" Authenticate a user based on mb_id as the user name. """ | |
try: | |
user = User.objects.get(mb_id=username) | |
if '$' not in user.password: | |
if self.check_legacy_password(user.password, password): | |
return user | |
else: | |
return None | |
else: | |
if user.check_password(password): | |
return user | |
except User.DoesNotExist: | |
return None | |
def get_user(self, user_id): | |
""" Get a User object from the user_id. """ | |
try: | |
return User.objects.get(pk=user_id) | |
except User.DoesNotExist: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment