When a user successfully login and come to home page there is a link "change password" for changing password .It displays a form to change password having three input box for old password, new password confirm new password
Here is my code.
forms.py
class reset_form(forms.Form):
oldpassword = forms.CharField(max_length = 20, widget=forms.TextInput(attrs={'type':'password', 'placeholder':'your old Password', 'class' : 'span'}))
newpassword1 = forms.CharField(max_length = 20, widget=forms.TextInput(attrs={'type':'password', 'placeholder':'New Password', 'class' : 'span'}))
newpassword2 = forms.CharField(max_length = 20, widget=forms.TextInput(attrs={'type':'password', 'placeholder':'Confirm New Password', 'class' : 'span'}))
def clean(self):
if 'newpassword1' in self.cleaned_data and 'newpassword2' in self.cleaned_data:
if self.cleaned_data['newpassword1'] != self.cleaned_data['newpassword2']:
raise forms.ValidationError(_("The two password fields did not match."))
return self.cleaned_data
views.py
def change_password(request):
if request.method == 'POST':
form = reset_form(request.POST)
if form.is_valid():
newpassword=form.cleaned_data['newpassword1'],
username=request.user.username
password=request.user.password
user = authenticate(username=username, password=password)
if user is not None:
user.set_password(newpassword)
user.save()
return HttpResponseRedirect('/reset/success/')
else:
return render(request, 'reset_password.html',{'error':'You have entered wrong old password','form': form})
else:
return render(request, 'reset_password.html',{'error':'You have entered old password','form': form})
else:
form = reset_form()
content = RequestContext(request, {'form': form})
return render(request, 'reset_password.html', content,)
After submitting the form with correct old password i am getting this message You have entered wrong old password I dont know why i am geeting this error message please help with this code