Py学习  »  问与答

[精华] authenticate()不能检验password

Dingo • 10 年前 • 16145 次点击  

使用authenticate()验证用户登录时,只能检验username。

部分代码:

user=authenticate(username=cduser['username'],password=cduser['password'])
if user is not None:
    return HttpResponse('success')
else:
    return HttpResponse('wrong')

现在情况是:登陆界面 输入username和password,提交表单以后, 如果username不存在,可以返回wrong。 如果username存在,不论password是什么,点击提交按钮在原页面停留,不会返回wrong或success。

AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', )设置过了

用的User.objects.create_user创建用户,密码应该是hash了的,在/admin里面看密码是hash了的。

cduser里储存的username和password是对的,我打印过。

求大神解决,十分感谢!

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/399
 
16145 次点击  
文章 [ 17 ]  |  最新文章 8 年前