Skip to content

Commit e378fb7

Browse files
Merge pull request #1423 from IFRCGo/feature/adding-more-password-policies
Stronger password policy: Aa1@ is mandatory.
2 parents 130c416 + 28e72a1 commit e378fb7

File tree

2 files changed

+69
-12
lines changed

2 files changed

+69
-12
lines changed

main/settings.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,18 +245,14 @@
245245
}
246246

247247
AUTH_PASSWORD_VALIDATORS = [
248-
{
249-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
250-
},
251-
{
252-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
253-
},
254-
{
255-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
256-
},
257-
{
258-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
259-
},
248+
{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', },
249+
{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', },
250+
{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', },
251+
{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', },
252+
{'NAME': 'main.validators.NumberValidator', },
253+
{'NAME': 'main.validators.UppercaseValidator', },
254+
{'NAME': 'main.validators.LowercaseValidator', },
255+
{'NAME': 'main.validators.SymbolValidator', },
260256
]
261257

262258
TINYMCE_DEFAULT_CONFIG = {

main/validators.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import re
2+
from django.core.exceptions import ValidationError
3+
from django.utils.translation import ugettext_lazy as _
4+
5+
6+
class NumberValidator(object):
7+
def validate(self, password, user=None):
8+
if not re.findall('\d', password):
9+
raise ValidationError(
10+
_("The password must contain at least 1 digit, 0-9."),
11+
code='password_no_number',
12+
)
13+
14+
def get_help_text(self):
15+
return _(
16+
"Your password must contain at least 1 digit, 0-9."
17+
)
18+
19+
20+
class UppercaseValidator(object):
21+
def validate(self, password, user=None):
22+
if not re.findall('[A-Z]', password):
23+
raise ValidationError(
24+
_("The password must contain at least 1 uppercase letter, A-Z."),
25+
code='password_no_upper',
26+
)
27+
28+
def get_help_text(self):
29+
return _(
30+
"Your password must contain at least 1 uppercase letter, A-Z."
31+
)
32+
33+
34+
class LowercaseValidator(object):
35+
def validate(self, password, user=None):
36+
if not re.findall('[a-z]', password):
37+
raise ValidationError(
38+
_("The password must contain at least 1 lowercase letter, a-z."),
39+
code='password_no_lower',
40+
)
41+
42+
def get_help_text(self):
43+
return _(
44+
"Your password must contain at least 1 lowercase letter, a-z."
45+
)
46+
47+
48+
class SymbolValidator(object):
49+
def validate(self, password, user=None):
50+
if not re.findall('[()[\]{}|\\`~!@#$%^&*_\-+=;:\'",<>./?]', password):
51+
raise ValidationError(
52+
_("The password must contain at least 1 symbol: " +
53+
"()[]{}|\`~!@#$%^&*_-+=;:'\",<>./?"),
54+
code='password_no_symbol',
55+
)
56+
57+
def get_help_text(self):
58+
return _(
59+
"Your password must contain at least 1 symbol: " +
60+
"()[]{}|\`~!@#$%^&*_-+=;:'\",<>./?"
61+
)

0 commit comments

Comments
 (0)