From fecef30ecc2dc31b81da1b2e82f5bc69088e525d Mon Sep 17 00:00:00 2001 From: Johan Lundberg Date: Mon, 4 Mar 2013 13:06:26 +0100 Subject: Added a TODO comment. --- forms.py | 35 +++++++++++++++++++++++++++++++++++ models.py | 34 ---------------------------------- 2 files changed, 35 insertions(+), 34 deletions(-) create mode 100644 forms.py delete mode 100644 models.py diff --git a/forms.py b/forms.py new file mode 100644 index 0000000..7db47a6 --- /dev/null +++ b/forms.py @@ -0,0 +1,35 @@ +from django import forms +import re + +class ChangePasswordForm(forms.Form): + new_password = forms.CharField(widget=forms.PasswordInput) + new_password_again = forms.CharField(widget=forms.PasswordInput) + + def clean(self): + ''' + Validate the password submitted. + ''' + cleaned_data = self.cleaned_data + # The two submitted strings need to match. + new_password = cleaned_data.get('new_password') + new_password_again = cleaned_data.get('new_password_again') + if new_password != new_password_again: + raise forms.ValidationError('The typed passwords do not \ +match.') + # Check that the length is at least 10 characters. + if not len(new_password) >= 10: + raise forms.ValidationError('Your password needs to be at \ +least 10 characters long. Currently %d characters.' % len(new_password)) + # The password needs to contain at least one upper and one lower case + # letter and three numbers or special characters. + if not re.search('[a-z]', new_password) or not re.search( + '[A-Z]', new_password): + raise forms.ValidationError('You need at least one upper \ +case letter and one lower case letter in your password.') + numbers = re.findall('\d', new_password) + # TODO: Update list of special characters, use \W. + specials = re.findall('[,.\[\]!@#$%^&*?_\(\)-]', new_password) + if (len(numbers)+len(specials)) < 3: + raise forms.ValidationError('You need at least three numbers or \ +special characters i.e. 1234567890,.][!@#$%^&*?_()-') + return cleaned_data \ No newline at end of file diff --git a/models.py b/models.py deleted file mode 100644 index 0451702..0000000 --- a/models.py +++ /dev/null @@ -1,34 +0,0 @@ -from django import forms -import re - -class ChangePasswordForm(forms.Form): - new_password = forms.CharField(widget=forms.PasswordInput) - new_password_again = forms.CharField(widget=forms.PasswordInput) - - def clean(self): - ''' - Validate the password submitted. - ''' - cleaned_data = self.cleaned_data - # The two submitted strings need to match. - new_password = cleaned_data.get('new_password') - new_password_again = cleaned_data.get('new_password_again') - if new_password != new_password_again: - raise forms.ValidationError('The typed passwords do not \ -match.') - # Check that the length is at least 10 characters. - if not len(new_password) >= 10: - raise forms.ValidationError('Your password needs to be at \ -least 10 characters long. Currently %d characters.' % len(new_password)) - # The password needs to contain at least one upper and one lower case - # letter and three numbers or special characters. - if not re.search('[a-z]', new_password) or not re.search( - '[A-Z]', new_password): - raise forms.ValidationError('You need at least one upper \ -case letter and one lower case letter in your password.') - numbers = re.findall('\d', new_password) - specials = re.findall('[,.\[\]!@#$%^&*?_\(\)-]', new_password) - if (len(numbers)+len(specials)) < 3: - raise forms.ValidationError('You need at least three numbers or \ -special characters i.e. 1234567890,.][!@#$%^&*?_()-') - return cleaned_data \ No newline at end of file -- cgit v1.1