Take the 2-minute tour ×

I use the method defined in django documentaion:http://www.djangobook.com/en/beta/chapter12/

def login(request):
    m = members.get_object(username__exact=request.POST['username'])
    if m.password == request.POST['password']:
        request.session['member_id'] = m.id
        return HttpResponse("You're logged in.")
        return HttpResponse("Your username and password didn't match.")

but that sounds like it doesn't match the password correctly! I enter a valid username and password but it doesn't find the user,when I remove this line,it works:

if m.password == request.POST['password']:

I think because that password is hashed,it doesn't match with plain password that user enter in login form.

so,what should I do now?

share|improve this question
You should use Django auth framework. –  DrTyrsa Oct 27 '11 at 10:53

2 Answers 2

up vote 4 down vote accepted

You should use user.check_password for this. The reason is that the password is stored hashed and you can not compare it directly like this.

P.S. Take a loot at how authentication backends work.

share|improve this answer

That's not supposed to be an example of how to do authentication. You'll find the real example a bit further down the page.

share|improve this answer
thank U ,this is a better solution –  Asma Gheisari Oct 27 '11 at 11:15

Your Answer


