The code that gathers the password policies in password_policy_password_element_alter overwrites the previous fetched ones.

I have two password policies and I noticed that only the first digit policy (out of total two password policies) was displayed.
Password policies

The problem is that the array is merged with keys here:

  foreach ($policies as $policy) {
    $items = $items + $policy->messages();
  }

Instead of just keep adding to an array independent on keys like this:

  foreach ($policies as $policy) {
    $items[] = $policy->messages();
  }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pontus_nilsson created an issue. See original summary.

pontus_nilsson’s picture

Status: Active » Needs review
FileSize
491 bytes

Patch added.

pontus_nilsson’s picture

Issue summary: View changes
pontus_nilsson’s picture

Issue summary: View changes
harivenuv’s picture

FileSize
89.79 KB

hi pontus_nilsson,

Thank you for report this issue. I have applied your patch but still issue here. I have attach a screenshot.

Password Policy

bmsomega’s picture

Wouldn't recommend using the dev version of this module. There is a recommended Drupa 7 version now that doesn't implement password_policy_password_element_alter. Instead, password validation is handled by password_policy_password_validate

bmsomega’s picture

Wouldn't recommend using the dev version of this module. There is a recommended Drupal 7 version now that doesn't implement password_policy_password_element_alter. Instead, password validation is handled by password_policy_password_validate

AohRveTPV’s picture

Title: Only first password policy displayed » Only one requirement message displayed for the same constraint from multiple policies
FileSize
867 bytes

Thank you, pontus_nilsson, for the bug report and patch.

As harivenuv found, #2 does not work. #2 is adding an array to the end of an array, making an array of arrays. Instead what we need is a single array with all the messages as strings.

I made a new patch that uses array_merge(). Please review and test. I found this bug affects not just the static list of requirements, but also the dynamic list of unmet requirements that is displayed as the password is entered.

Ideally, the same constraints from multiple policies would be collapsed into one where possible. For instance, requiring 4 digits and requiring 3 digits could be collapsed to just requiring 4 digits. Doing that would add complexity to the code though; I think it's fine for now to display redundant constraints.

  • AohRveTPV committed 63ae298 on 7.x-2.x
    Issue #2688137 by pontus_nilsson, AohRveTPV, harivenuv: Only one...
AohRveTPV’s picture

Status: Needs review » Fixed

Went ahead and committed #8 so it can get some testing through use. Should be OK since we're in alpha.

Please report if anything needs changing.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.