0

I am working on a password reset for django, but whatever I try the reset doesn't work. So i checked what my form handled on data which i knew had to be true. It still didn't work. So alst i tried to authenticate in the django shell. and this is what happened.

shell:

In [11]: user = User.objects.first()
In [12]: password = "bier"
In [13]: user.set_password(password)
In [14]: i = authenticate(username=user.username, password=password)
In [15]: i
i returns None

Someone any clue about what is causing this?

3

2 Answers 2

4

You should save your user object,

user.save()

According to the docs, user object is not saved:

"Sets the user’s password to the given raw string, taking care of the password hashing. Doesn’t save the User object."

https://docs.djangoproject.com/en/1.8/ref/contrib/auth/#django.contrib.auth.models.User.set_password

Sign up to request clarification or add additional context in comments.

Comments

0
from django.contrib.auth.models import User
u = User.objects.get(username='john')
u.set_password('new password')
u.save()

https://docs.djangoproject.com/en/dev/topics/auth/default/#changing-passwords https://docs.djangoproject.com/en/dev/topics/auth/default/#authenticating-users

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.