def test_validate_password_entropy(self): password_unsafe = 'hello' self.assertLess(password_strength(password_unsafe)['entropy'], 50) with self.assertRaises(ValidationError): validate_password_entropy(password_unsafe) password_safe = 'helloThisIsAVeryLongPasswordWithMoreEntropyThan10!' self.assertGreaterEqual(password_strength(password_safe)['entropy'], 50) self.assertIsNone(validate_password_entropy(password_safe))
def test_actor_update_password_meta(self): self.actor_a.set_password('0') my_password = '******' pws = password_strength(my_password) self.actor_a.update_password_meta(my_password) self.assertEqual(self.actor_a.password_entropy, pws['entropy']) self.assertEqual(self.actor_a.password_score, pws['score'])
def test_actor_set_password(self): self.actor_a.set_password('0') my_password = '******' pws = password_strength(my_password) self.actor_a.set_password(my_password) self.assertEqual(self.actor_a.password_entropy, pws['entropy']) self.assertEqual(self.actor_a.password_score, pws['score']) self.assertFalse(self.actor_a.password_force_change) self.assertIsNone(self.actor_a.password_recovery_token) self.assertTrue(self.actor_a.check_password(my_password))
def validate_password_entropy(value): default_minimum = 0 try: password_minimum_entropy = Site.objects.get_current().configuration.password_minimum_entropy or default_minimum except ObjectDoesNotExist: password_minimum_entropy = default_minimum value_entropy = password_strength(value)['entropy'] if value_entropy < password_minimum_entropy: raise ValidationError(_('Das Passwort ist noch nicht stark genug. Bitte mehr unterschiedliche Zeichen ' 'eingeben.'))