Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_password_is_complex(self):
# one lower one upper one digit 8 chars
self.assertTrue(is_password_complex('Ab1.....'))
self.assertTrue(is_password_complex(' Ab1 '))
# password is longer than 12 chars
self.assertTrue(is_password_complex('longer than twelve characters'))
def test_password_is_not_complex(self):
# length < 8
self.assertFalse(is_password_complex('only5'))
# length < 12
self.assertFalse(is_password_complex('only11chars'))
# 8 < length < 12, no dig, no cap
self.assertFalse(is_password_complex('nodignocap'))
# 8 < length < 12, no cap
self.assertFalse(is_password_complex('okd1gnocap'))
# 8 < length < 12, no dig
self.assertFalse(is_password_complex('nodigokCap'))
# 8 < length < 12, no low
self.assertFalse(is_password_complex('OKD1GOKCAP'))
def test_password_is_not_complex(self):
# length < 8
self.assertFalse(is_password_complex('only5'))
# length < 12
self.assertFalse(is_password_complex('only11chars'))
# 8 < length < 12, no dig, no cap
self.assertFalse(is_password_complex('nodignocap'))
# 8 < length < 12, no cap
self.assertFalse(is_password_complex('okd1gnocap'))
# 8 < length < 12, no dig
self.assertFalse(is_password_complex('nodigokCap'))
# 8 < length < 12, no low
self.assertFalse(is_password_complex('OKD1GOKCAP'))
def test_password_is_not_complex(self):
# length < 8
self.assertFalse(is_password_complex('only5'))
# length < 12
self.assertFalse(is_password_complex('only11chars'))
# 8 < length < 12, no dig, no cap
self.assertFalse(is_password_complex('nodignocap'))
# 8 < length < 12, no cap
self.assertFalse(is_password_complex('okd1gnocap'))
# 8 < length < 12, no dig
self.assertFalse(is_password_complex('nodigokCap'))
# 8 < length < 12, no low
self.assertFalse(is_password_complex('OKD1GOKCAP'))
def test_password_is_complex(self):
# one lower one upper one digit 8 chars
self.assertTrue(is_password_complex('Ab1.....'))
self.assertTrue(is_password_complex(' Ab1 '))
# password is longer than 12 chars
self.assertTrue(is_password_complex('longer than twelve characters'))
def test_password_is_complex(self):
# one lower one upper one digit 8 chars
self.assertTrue(is_password_complex('Ab1.....'))
self.assertTrue(is_password_complex(' Ab1 '))
# password is longer than 12 chars
self.assertTrue(is_password_complex('longer than twelve characters'))
def test_password_is_not_complex(self):
# length < 8
self.assertFalse(is_password_complex('only5'))
# length < 12
self.assertFalse(is_password_complex('only11chars'))
# 8 < length < 12, no dig, no cap
self.assertFalse(is_password_complex('nodignocap'))
# 8 < length < 12, no cap
self.assertFalse(is_password_complex('okd1gnocap'))
# 8 < length < 12, no dig
self.assertFalse(is_password_complex('nodigokCap'))
# 8 < length < 12, no low
self.assertFalse(is_password_complex('OKD1GOKCAP'))
def test_password_is_not_complex(self):
# length < 8
self.assertFalse(is_password_complex('only5'))
# length < 12
self.assertFalse(is_password_complex('only11chars'))
# 8 < length < 12, no dig, no cap
self.assertFalse(is_password_complex('nodignocap'))
# 8 < length < 12, no cap
self.assertFalse(is_password_complex('okd1gnocap'))
# 8 < length < 12, no dig
self.assertFalse(is_password_complex('nodigokCap'))
# 8 < length < 12, no low
self.assertFalse(is_password_complex('OKD1GOKCAP'))
def clean_confirm_new_password(self):
if 'new_password' not in self.cleaned_data:
return None
if not self.cleaned_data['confirm_new_password'] and self.cleaned_data['new_password']:
raise forms.ValidationError(_("Confirm your new password by entering it here"))
if self.cleaned_data['new_password'] != self.cleaned_data['confirm_new_password']:
raise forms.ValidationError(_("Mismatch between your new password and confirmation, try again"))
password = self.cleaned_data['new_password']
if password and not is_password_complex(password):
raise forms.ValidationError(_("Passwords must have at least 8 characters, including one uppercase, "
"one lowercase and one number"))
if password and PasswordHistory.is_password_repeat(self.instance, password):
raise forms.ValidationError(_("You have used this password before in the past year, "
"please use a new password."))
return self.cleaned_data['new_password']
def clean_new_password(self):
password = self.cleaned_data['new_password']
if password and not is_password_complex(password):
raise forms.ValidationError(_("Passwords must have at least 8 characters, including one uppercase, "
"one lowercase and one number"))
if password and PasswordHistory.is_password_repeat(self.instance, password):
raise forms.ValidationError(_("You have used this password before in the past year, "
"please use a new password."))
return password