验证不返回任何内容 [英] authenticate returns nothing

查看:119
本文介绍了验证不返回任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  S:\proj> manage.py shell 
Python 2.5 .4(r254:67916,2008年12月23日,15:10:54)django 1.1.1

>>>来自django.contrib.auth.models import User
>>> u = User(username ='luis',password ='admin')
>>> u.save()#sucessfull在mysql中创建db
>>>来自django.contrib.auth import authenticate
>>> usuario = authenticate(username ='luis',password ='admin')
>>> usuario
>>>

认证无返回,我缺少什么?

解决方案

问题不在于认证,而是您创建该用户。



存储在 u.password 中的值需要是密码的哈希值,而不是原始密码本身。



您可以使用 u.set_password('password')来处理哈希:

 >>> u = User(name ='luis')
>>> u.set_password('password')
>>> u.save()
>>> authenticate(username ='luis',password ='password')
< User:luis>


what im experimenting is the next:

S:\proj>manage.py shell
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) django 1.1.1

>>> from django.contrib.auth.models import User
>>> u = User(username='luis', password='admin')
>>> u.save() #sucessfull created in mysql db
>>> from django.contrib.auth import authenticate
>>> usuario = authenticate(username='luis', password='admin')
>>> usuario
>>>

authenticate return nothing, what I am missing?

解决方案

The problem is not with authenticate, but with your creation of the user.

The value stored in u.password needs to be the hashed value of the password, not the raw password itself.

You can use u.set_password('password') to take care of the hashing for you:

>>> u = User(name='luis')
>>> u.set_password('password')
>>> u.save()
>>> authenticate(username='luis', password='password')
<User: luis>

这篇关于验证不返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆