Login

Password Reset Form Newforms

Author:
glisha
Posted:
April 5, 2007
Language:
Python
Version:
.96
Tags:
newforms password-reset
Score:
1 (after 3 ratings)

A Change Password form that asks the user for the old password and checks the two new passwords.

Whenever you instantiate the form you must pass a User object to it. ex. theform = forms.PasswordReset(request.user,request.POST)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
class PasswordReset(forms.Form):
    oldpassword = forms.CharField(widget=PasswordInput())
    password1 = forms.CharField(widget=PasswordInput())
    password2 = forms.CharField(widget=PasswordInput())

    def __init__(self, user, *args, **kwargs):
        self.user = user
        super(PasswordReset, self).__init__(*args, **kwargs)

    def clean_oldpassword(self):
        if self.clean_data.get('oldpassword') and not self.user.check_password(self.clean_data['oldpassword']):
            raise ValidationError('Please type your current password.')
        return self.clean_data['oldpassword']

    def clean_password2(self):
        if self.clean_data.get('password1') and self.clean_data.get('password2') and self.clean_data['password1'] != self.clean_data['password2']:
            raise ValidationError('The new passwords are not the same')
        return self.clean_data['password2']

More like this

  1. Simple E-mail registration by bthomas 6 years, 8 months ago
  2. reset django password by hugogee 3 years, 11 months ago
  3. New forms signup validation by Batiste 8 years, 3 months ago
  4. Reset / Send account details email by Ciantic 4 years, 12 months ago
  5. use oldforms validators in newforms forms by garywilson 8 years, 3 months ago

Comments

akaihola (on October 15, 2007):

How to clear the three password fields when re-displaying the form after either a successful or unsuccessful POST?

I don't think it's a good idea to echo back the old and new passwords in the form as field values.

#

Please login first before commenting.