Why would check_password(..) return True but authenticate(.., ..) never return user?

99 views
Skip to first unread message

Christian Seberino

unread,
Oct 6, 2019, 8:22:00 PM10/6/19
to Django users
Why would check_password(..) return True but authenticate(.., ..) never return user?

See this session in a Django shell below...

>>> u
<User: xx>

>>> u.username
'xx'

>>> u.password
'pbkdf2_sha256$100000$f3zIUwPXtnEM$zbQdcgPNgRi6CBPQu8wlRg4T7egH80S9bnL0FPunZRo='

>>> u.check_password("yy")
True

>>> django.contrib.auth.authenticate(username="xx", password="yy")
>>>

Pradeep Sukhwani

unread,
Oct 7, 2019, 4:00:52 AM10/7/19
to Django users
Hi Christian,

authentication() functions takes request parameter if the request is None it will simply

break
the for loop. Check the source code of authenticate.


--
Thanks
Pradeep Sukhwani

Christian Seberino

unread,
Oct 7, 2019, 11:00:15 AM10/7/19
to Django users
Thanks. I tried doing authenticate(request = request, username = username, password = password)
and it still fails.  Also, they mention the request parameter in Django docs but then 
the example does not have it!!!!  See


After the example it says the request parameter is optional.

Still doesn't work. :(

Any help greatly appreciated still.

Chris

Christian Seberino

unread,
Oct 7, 2019, 2:03:36 PM10/7/19
to Django users
OK I fixed.

All my server code was correct but I was creating User objects incorrectly.

You can create User objects in such a way that they are NOT utilized
correctly by the authentication system!

I was not using the User.objects.create_user method.
Once I did that, it worked.

Chris
Reply all
Reply to author
Forward
0 new messages