Answer the question
In order to leave comments, you need to log in
Changing a user's password in Django?
I am making a personal account where the user can change the password. To do this, he must first enter the old password, and I need to check that it is correct. How to encrypt the password entered by the user so that it matches the one in the database during verification?
Answer the question
In order to leave comments, you need to log in
def a_change_password(request):
u = User.objects.get(username=request.user)
if request.method == 'POST':
form = ChangePasswordForm(request.POST)
if form.is_valid():
old_password = request.POST.get("old_password")
new_pass = request.POST.get("new_password")
new_pass_rep = request.POST.get("new_password_repeat")
if check_password(old_password,u.password):
return HttpResponse('ok')
else:
return HttpResponse('bad')
else:
form = ChangePasswordForm()
return render(request, 'login/change_password.html',
{'form': form, 'user': u})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question