Reputation: 11
if request.method=='POST':
try:
email=request.POST['email']
password = request.POST['password']
if StudentUser.objects.filter(email=email).exists():
user = StudentUser.objects.get(email=email)
if user.check_password(password):
user = auth.authenticate(email=email)
if user is not None:
auth.login(request,user)
messages.success(request,'Successfully Loggedin')
return redirect('/')
else:
messages.warning(request,'Password does not match')
return redirect('login')
else:
messages.error(request,'No Account registered with this mail')
return redirect('login')
except Exception as problem:
messages.error(request,problem)
return redirect('login')
return render(request,'login.html')
This above code i am trying to authenticate the user manually, but it is not working. i want to authenticate a user by manually checking the password. How can i do it?
** when I am passing the password in auth.authenticate function it is showing password does not match error
Upvotes: 1
Views: 3173
Reputation: 15738
You should pass password as argument to authenticate method
From docs
user = authenticate(username='john', password='secret')
Use authenticate() to verify a set of credentials. It takes credentials as keyword arguments, username and password for the default case, checks them against each authentication backend, and returns a User object if the credentials are valid for a backend.
Upvotes: 2