LaundroMat wrote:
> Hi,
> 
> When running this, I get a "NoneType has no attribute
> is_authenticated()" error, and I cannot understand why:
> 
> 1 new_user = User.objects.create_user(username, "your.email",
> password)
> 2 new_user.is_active = False
> 3 new_user.save()
> 4 user = authenticate(username = new_user.username, password =
> new_user.password) # See http://code.djangoproject.org/ticket/2656
> 5 if user.is_authenticated():   # The error is produced here.
>     login(request, user)
> 
> Why does authenticate() in line 4 return a None object instead of a
> user?
> 
> Thanks for your help,
> 
> Mathieu

"If the password is invalid, authenticate() returns None" [1]

The password field in the User model contains "...a hash of, and 
metadata about, the password. (Django doesn't store the raw password.)" [2]

So authenticate is returning None because you're trying to login with a 
hashed version of the password, not the raw version. Try this instead:

     user = authenticate(username=username, password=password)

Look at the second code example under [1] for an example of how to do this.

Jonathan.

[1] 
http://www.djangoproject.com/documentation/authentication/#how-to-log-a-user-in

[2] http://www.djangoproject.com/documentation/authentication/#fields

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to