Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
033da3c0
Commit
033da3c0
authored
Jan 11, 2017
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
authentication_policy: return messages directly in Login_analyzePassword
parent
cc578417
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
19 deletions
+19
-19
bt5/erp5_authentication_policy/SkinTemplateItem/portal_skins/erp5_authentication_policy/Login_analyzePassword.py
...skins/erp5_authentication_policy/Login_analyzePassword.py
+16
-8
bt5/erp5_authentication_policy/SkinTemplateItem/portal_skins/erp5_authentication_policy/Login_isPasswordValid.py
...skins/erp5_authentication_policy/Login_isPasswordValid.py
+3
-11
No files found.
bt5/erp5_authentication_policy/SkinTemplateItem/portal_skins/erp5_authentication_policy/Login_analyzePassword.py
View file @
033da3c0
"""
Returns if password is valid or not.
If not valid return a negative code to indicate failure.
Returns the list of messages in case a password does not comply with the policy
"""
from
Products.
Formulator.Errors
import
ValidationError
from
Products.
ERP5Type.Message
import
translateString
from
DateTime
import
DateTime
import
re
MARKER
=
[
''
,
None
]
message_dict
=
{
0
:
'Unknown error'
,
-
1
:
'Too short.'
,
-
2
:
'Not complex enough.'
,
-
3
:
'You have changed your password too recently.'
,
-
4
:
'You have already used this password.'
,
-
5
:
'You can not use any parts of your first and last name in password.'
}
def
addError
(
error_code
):
result_code_list
.
append
(
translateString
(
message_dict
[
error_code
]))
portal
=
context
.
getPortalObject
()
request
=
context
.
REQUEST
...
...
@@ -22,7 +30,7 @@ if password is None:
# not long enough
if
min_password_length
is
not
None
:
if
len
(
password
)
<
min_password_length
:
result_code_list
.
append
(
-
1
)
addError
(
-
1
)
# password contain X out of following Y regular expression groups ?
regular_expression_list
=
portal
.
portal_preferences
.
getPreferredRegularExpressionGroupList
()
...
...
@@ -36,7 +44,7 @@ if regular_expression_list:
#context.log('%s %s %s %s' %(password, group_counter, min_regular_expression_group_number, regular_expression_list))
if
group_counter
<
min_regular_expression_group_number
:
# not enough groups match
result_code_list
.
append
(
-
2
)
addError
(
-
2
)
if
not
is_temp_object
:
# not changed in last period ?
...
...
@@ -57,13 +65,13 @@ if not is_temp_object:
min_password_lifetime_duration
is
not
None
and
\
(
last_password_modification_date
+
min_password_lifetime_duration
*
one_hour
)
>
now
:
# too early to change password
result_code_list
.
append
(
-
3
)
addError
(
-
3
)
# not already used before ?
preferred_number_of_last_password_to_check
=
portal
.
portal_preferences
.
getPreferredNumberOfLastPasswordToCheck
()
if
preferred_number_of_last_password_to_check
not
in
[
None
,
0
]:
if
context
.
isPasswordAlreadyUsed
(
password
):
result_code_list
.
append
(
-
4
)
addError
(
-
4
)
# not contain the full name of the user in password or any parts of it (i.e. last and / or first name)
if
portal
.
portal_preferences
.
isPrefferedForceUsernameCheckInPassword
():
...
...
@@ -85,6 +93,6 @@ if portal.portal_preferences.isPrefferedForceUsernameCheckInPassword():
if
(
first_name
not
in
MARKER
and
first_name
in
lower_password
)
or
\
(
last_name
not
in
MARKER
and
last_name
in
lower_password
):
# user's name must not be contained in password
result_code_list
.
append
(
-
5
)
addError
(
-
5
)
return
result_code_list
bt5/erp5_authentication_policy/SkinTemplateItem/portal_skins/erp5_authentication_policy/Login_isPasswordValid.py
View file @
033da3c0
...
...
@@ -6,19 +6,11 @@ from Products.Formulator.Errors import ValidationError
portal
=
context
.
getPortalObject
()
message_dict
=
{
0
:
'Unknown error'
,
-
1
:
'Too short.'
,
-
2
:
'Not complex enough.'
,
-
3
:
'You have changed your password too recently.'
,
-
4
:
'You have already used this password.'
,
-
5
:
'You can not use any parts of your first and last name in password.'
}
def
doValidation
(
login
,
password
):
# raise so Formulator shows proper message
result_code_list
=
login
.
analyzePassword
(
password
)
if
result_code_list
!=
[]:
translateString
=
context
.
Base_translateString
message
=
' '
.
join
([
translateString
(
message_dict
[
x
])
for
x
in
result_code_list
])
result_message_list
=
login
.
analyzePassword
(
password
)
if
result_message_list
:
message
=
u' '
.
join
([
str
(
x
)
for
x
in
result_message_list
])
raise
ValidationError
(
'external_validator_failed'
,
context
,
error_text
=
message
)
return
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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