S
S
Socrates2018-02-07 16:58:21
Django
Socrates, 2018-02-07 16:58:21

In the view.py file, change the user's password?

Can I change the user's password in view.py?

if edit_form.is_valid() and edit_userForm.is_valid() and resetPassData.is_valid():
            oldPass = resetPassData.cleaned_data["old_password"]
            newPass = resetPassData.cleaned_data["new_password"]
            if oldPass!="" and newPass!="":
                if oldPass == newPass:
                    print("Пароли не должны совпадать")
                    resPassError = "Пароли не должны совпадать"
                else:
                    print("Пароль изменен")

Of course, everything is not the best for me there, but tell me if there is such an opportunity to refer to the User.password model and change it to the one received from the form.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-02-07
@Karmov69

Nobody reads the documentation :(

from django.contrib.auth.models import User

u = User.objects.get(username='john')
u.set_password('new password')
u.save()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question