Skip to content

Commit 1a8e040

Browse files
refactor(validators): Simplify and refactor password validators
This commit refactors the password validation classes to improve clarity, reduce complexity, and align better with Django conventions. The key changes include: - Removed the `BaseCountPasswordValidator` abstract base class, as it added unnecessary complexity. Each validator is now a self-contained class. - Simplified the logic within each validator, using more direct and efficient methods for character checks (e.g., `isascii()`, `isupper()`). - Renamed validator classes for conciseness (e.g., `ASCIIOnlyPasswordValidator` to `AsciiValidator`). - Improved internationalization and pluralization of error messages by using `ngettext`. - Updated `settings.py` to reflect the new validator class names and their simplified options.
1 parent 90b6ce0 commit 1a8e040

File tree

2 files changed

+137
-189
lines changed

2 files changed

+137
-189
lines changed

promo_code/promo_code/settings.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,27 +178,23 @@ def load_bool(name, default):
178178
'.NumericPasswordValidator',
179179
},
180180
{
181-
'NAME': 'promo_code.validators.ASCIIOnlyPasswordValidator',
181+
'NAME': 'promo_code.validators.AsciiValidator',
182182
},
183183
{
184-
'NAME': 'promo_code.validators.SpecialCharacterPasswordValidator',
185-
'OPTIONS': {'min_count': 1},
184+
'NAME': 'promo_code.validators.SpecialCharacterValidator',
185+
'OPTIONS': {'special_chars': '[@$!%*?&]'},
186186
},
187187
{
188-
'NAME': 'promo_code.validators.NumericPasswordValidator',
189-
'OPTIONS': {'min_count': 1},
188+
'NAME': 'promo_code.validators.NumericValidator',
190189
},
191190
{
192-
'NAME': 'promo_code.validators.LowercaseLatinLetterPasswordValidator',
193-
'OPTIONS': {'min_count': 1},
191+
'NAME': 'promo_code.validators.LowercaseValidator',
194192
},
195193
{
196-
'NAME': 'promo_code.validators.UppercaseLatinLetterPasswordValidator',
197-
'OPTIONS': {'min_count': 1},
194+
'NAME': 'promo_code.validators.UppercaseValidator',
198195
},
199196
]
200197

201-
202198
PASSWORD_HASHERS = [
203199
'django.contrib.auth.hashers.Argon2PasswordHasher',
204200
'django.contrib.auth.hashers.PBKDF2PasswordHasher',

0 commit comments

Comments
 (0)