Coverage for utilities/password_validation.py: 56%

12 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 18:35 +0000

1from django.core.exceptions import ValidationError 

2from django.utils.translation import gettext as _ 

3 

4 

5class AlphanumericPasswordValidator: 

6 """ 

7 Validate that the password has at least one numeral, one uppercase letter and one lowercase letter. 

8 """ 

9 

10 def validate(self, password, user=None): 

11 if not any(char.isdigit() for char in password): 11 ↛ 12line 11 didn't jump to line 12 because the condition on line 11 was never true

12 raise ValidationError( 

13 _("Password must have at least one numeral."), 

14 ) 

15 

16 if not any(char.isupper() for char in password): 16 ↛ 21line 16 didn't jump to line 21 because the condition on line 16 was always true

17 raise ValidationError( 

18 _("Password must have at least one uppercase letter."), 

19 ) 

20 

21 if not any(char.islower() for char in password): 

22 raise ValidationError( 

23 _("Password must have at least one lowercase letter."), 

24 ) 

25 

26 def get_help_text(self): 

27 return _("Your password must contain at least one numeral, one uppercase letter and one lowercase letter.")