views:

29

answers:

1

Hi, 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?

+1  A: 

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>
Ben James
faaaaaaaaaaaaast and furiousssssss
panchicore