I am new to Django and I was creating a simple user registration page. I am able to create new users from my register.html page. I can see the users are created in the django's built-in administration page. However when I try to login into my website with the newly created user, I am redirected to error page.
def newuser(request):
if request.method == "POST":
email = request.POST.get('email','')
password = request.POST.get('password','')
user, created = User.objects.get_or_create(username=email, email=email)
if created:
user.set_password(password)
user.save()
return HttpResponseRedirect('/master/messages')
else:
return HttpResponseRedirect('/master/invalid')
It seems that the password is not getting saved in hashed format. When I reset the password from admin page, I can login with the new password. Can anyone suggest how can I fix this?