[Answered ]-Not able to authenticate user in Django?

1👍

You shouldn’t be hashing the submitted password in the view. The backend does that for you when you call the User.check_password method.

1👍

Change in your view

def login_backend(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        #password = hashlib.sha1(password).hexdigest()
        #user = authenticate(username=username, password=password)
        state = "Username or Password Incorrect!"
        if user is not None:
            login(request, user)
            return HttpResponseRedirect('/overview/')
        else:
            return render_to_response('login_backend.html', {'state':state}, context_instance=RequestContext(request))
    else:
        return render_to_response('login_backend.html', context_instance=RequestContext(request))

Leave a comment