I'm transferring a database to a new project and more precisely the users. Don't ask me why but the passwords in the old database were hashed with md5 and then with sha256.
I'm using django-rest-auth to manage login.
url(r'^api/rest-auth/', include('rest_auth.urls')),
I added a custom authentication method:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'users.auth.OldCustomAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
)
}
Here is my auth file:
class OldCustomAuthentication(BaseAuthentication):
def authenticate(self, request):
try:
password = request.POST['password']
email = request.POST['email']
except MultiValueDictKeyError:
return None
if not password or not email:
return None
password = hashlib.md5(password.encode())
password = hashlib.sha256(password.hexdigest().encode())
try:
user = User.objects.get(email=email, password=password.hexdigest())
except User.DoesNotExist:
return None
# User is found every time
print('FOUND USER', user)
return user, None
But I still get an error when I request http://apiUrl/rest-auth/login/:
{
"non_field_errors": [
"Unable to log in with provided credentials."
]
}
Do you have any idea? Or maybe I'm doing it in a wrong way.
Thank you in advance.
Jeremy.