Skip to content

Instantly share code, notes, and snippets.

@zodman
Created June 17, 2013 21:22
Show Gist options
  • Save zodman/5800585 to your computer and use it in GitHub Desktop.
Save zodman/5800585 to your computer and use it in GitHub Desktop.
pasword enhanced, stupid whim
def clean_password2(self):
import string
password1 = self.cleaned_data.get("password1", "")
password2 = self.cleaned_data["password2"]
if password1 != password2:
raise forms.ValidationError(_("The two password fields didn't match."))
if len(password2) <6:
raise forms.ValidationError(_("The password must be almost 6 chars"))
digits, chars, punt = set(), set(), set()
for i in password2:
if i.isdigit():
digits.add(i)
if ord(i) < 128:
chars.add(i)
if i in string.punctuation:
punt.add(i)
if not len(digits) >=1 or not len(chars)>=1 or not len(punt)>=1:
raise forms.ValidationError(_("One char, one digit or one puntaction required"))
return password2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment