I wrote a custom backend for my application to process logins in a sort-of unique way, as I have specific needs for this project. Here’s my backend:
from my.project.models import User
from hashlib import sha512
class MyBackend:
def authenticate(self, email_address=None, password=None):
print "Trying to auth: " + email_address
try:
user = User.objects.get(email_address=email_address)
password = sha512(password + user.password_salt).hexdigest()
if user.password != password:
return None
else:
return user
except User.DoesNotExist:
return None
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
Here’s my User class:
class User(models.Model):
email_address = models.EmailAddressField()
password = models.CharField(max_length=128)
password_salt = models.CharField(max_length=128)
It’s pretty simple, but I’ve already built the rest of my models around this ‘User’ class.
Is there a way to make this work so as to have the best of both worlds, or should I ditch this approach and just use Django’s built-in model for users?
Extending the user can best be done by using user profiles.
Define a user profile-model and at the bottom, add something like this:
I think this approach might be better than replacing the User-model