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): ...@@ -60,6 +60,13 @@ class ILoginAccountProvider(Interface):
Is password valid? 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): def isPasswordAlreadyUsed(self, password):
""" """
Return if password has already been used. Return if password has already been used.
......
...@@ -82,10 +82,19 @@ class LoginAccountProviderMixin: ...@@ -82,10 +82,19 @@ class LoginAccountProviderMixin:
""" """
Is password valid? Is password valid?
""" """
method = self._getTypeBasedMethod('isPasswordValid') result_code_list = self.analyzePassword(password, **kw)
if method is not None: if not len(result_code_list):
return method(password, **kw)
return True 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') security.declareProtected(Permissions.SetOwnPassword, 'isPasswordAlreadyUsed')
def isPasswordAlreadyUsed(self, password): def isPasswordAlreadyUsed(self, password):
...@@ -93,9 +102,13 @@ class LoginAccountProviderMixin: ...@@ -93,9 +102,13 @@ class LoginAccountProviderMixin:
Return if password has already been used. Return if password has already been used.
""" """
preferred_number_of_last_password_to_check = self.portal_preferences.getPreferredNumberOfLastPasswordToCheck() preferred_number_of_last_password_to_check = self.portal_preferences.getPreferredNumberOfLastPasswordToCheck()
password_list = self.getLastChangedPasswordValueList() password_event_list = self.getPortalObject().portal_catalog(
password_list.reverse() portal_type = "Password Event",
for encoded_password in password_list[:preferred_number_of_last_password_to_check]: 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): if pw_validate(encoded_password, password):
return True return True
return False 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