Commit 7e9f03f3 authored by Ivan Tyagov's avatar Ivan Tyagov

Allow UI to show all password validation error messages by extending

API.
Adjust test accordingly.
parent 65610e6b
......@@ -60,6 +60,13 @@ class ILoginAccountProvider(Interface):
Is password valid?
"""
def analyzePassword(password, **kw):
"""
Analyze password validity.
Return status code indicating if password is acceptable and if not status code
for reason for not being a valid one (i.e. too short, not complex, etc ...)
"""
def isPasswordAlreadyUsed(self, password):
"""
Return if password has already been used.
......
......@@ -82,10 +82,19 @@ class LoginAccountProviderMixin:
"""
Is password valid?
"""
method = self._getTypeBasedMethod('isPasswordValid')
if method is not None:
return method(password, **kw)
result_code_list = self.analyzePassword(password, **kw)
if not len(result_code_list):
return True
return False
def analyzePassword(self, password, **kw):
"""
Analyze password validity.
Return status code indicating if password is acceptable and if not status code
for reason for not being a valid one (i.e. too short, not complex, etc ...)
"""
method = self._getTypeBasedMethod('analyzePassword')
return method(password, **kw)
security.declareProtected(Permissions.SetOwnPassword, 'isPasswordAlreadyUsed')
def isPasswordAlreadyUsed(self, password):
......@@ -93,9 +102,13 @@ class LoginAccountProviderMixin:
Return if password has already been used.
"""
preferred_number_of_last_password_to_check = self.portal_preferences.getPreferredNumberOfLastPasswordToCheck()
password_list = self.getLastChangedPasswordValueList()
password_list.reverse()
for encoded_password in password_list[:preferred_number_of_last_password_to_check]:
password_event_list = self.getPortalObject().portal_catalog(
portal_type = "Password Event",
default_destination_uid = self.getUid(),
sort_on = (('creation_date', 'DESC',),),
limit = preferred_number_of_last_password_to_check)
password_list = [x.getPassword() for x in password_event_list]
for encoded_password in password_list:
if pw_validate(encoded_password, password):
return True
return False
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment