Pankaj Pankaj - 23 days ago 18
Python Question

How to login with encrypted password in django

I am using django.contrib.auth for authentication in my project, its working fine, Now i have to work on a module where super members have to login in it's member's account, he should have all the access of their account,

so I have to login with member's email id and their encrypted password automatically saved by django Auth while registering members.

user_existence = User.objects.filter(email=request.POST['email']).first()
if user_existence:
email = user_existence.email
password = user_existence.password
user = authenticate(username=email, password=password)
if user is not None:
login(request, user)
return HttpResponse('user_connected')
return HttpResponse('user_auth_failed')


Is is possible to encrypt this password or login with encrypted password, or it would be great if its having another solution.

Answer

You can simply log in as a certain user using

 user = User.objects.get(email=request.POST['email'])
 user.backend = 'django.contrib.auth.backends.ModelBackend'
 login(request, user)

No need to run

 authenticate()
Comments