Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
DIGIPUS
Commits
ec71aef3
Commit
ec71aef3
authored
Oct 29, 2020
by
Gregorius Aprisunnea
Browse files
implementing PasswordValidator and uncommenting other tests
parent
1e4a8b7d
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
app/tests.py
View file @
ec71aef3
This diff is collapsed.
Click to expand it.
app/utils/PasswordValidator.py
View file @
ec71aef3
import
string
from
django.core.exceptions
import
ValidationError
class
PasswordPolicyValidator
(
object
):
def
validate
(
self
,
password
,
user
=
None
):
if
sum
(
c
.
isdigit
()
for
c
in
password
)
<
1
:
msg
=
'Password must contain at least 1 number.'
raise
ValidationError
(
msg
)
if
not
any
(
c
.
isupper
()
for
c
in
password
):
msg
=
'Password must contain at least 1 uppercase letter.'
raise
ValidationError
(
msg
)
if
not
any
(
c
.
islower
()
for
c
in
password
):
msg
=
'Password must contain at least 1 lowercase letter.'
raise
ValidationError
(
msg
)
if
not
any
(
c
for
c
in
password
if
c
in
string
.
punctuation
):
msg
=
'Password must contain at least 1 special letter.'
raise
ValidationError
(
msg
)
if
len
(
password
)
<
8
:
msg
=
'Password must have at least 8 characters.'
raise
ValidationError
(
msg
)
def
get_help_text
(
self
):
return
_
(
"Your password is not complying to our password policy"
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment