Putting more than one password_confirm form element on a page breaks both the behavior and the visual appearance of these elements. Specifically, the strength indicator bar no longer works, the text indication of the password strength no longer appears, the validation (matching) in JavaScript breaks (it will always say the two textfields match regardless of content), and the indicator labels (i.e. "Password strength:" and "Passwords match:") are displayed multiple times on each password_confirm.

There are two problems in the code that cause this:

First, several elements added to the DOM from within user.js have a CSS id hardwired. When two password_confirms are on the page the JavaScript fails because there are multiple elements with the same id. The attached patch changes id to class in the JavaScript, with a corresponding fix in the CSS files.

Second, in user.module, the function user_form_process_password_confirm() adds JavaScript settings to the page once for every password_confirm element. When more than one password_confirm element appears on the page, each of the settings becomes an array instead of a string. The JavaScript in user.js always expects strings, and breaks when it receives an array. The attached patch avoids this problem by using a static flag to ensure the settings are only added once. Note that the root cause of this is described in #208611: Add drupal_array_merge_deep() and drupal_array_merge_deep_array() to stop drupal_add_js() from adding settings twice, but the fix will work regardless of what is eventually done in that issue.

In the course of debugging this issue, I discovered several extraneous, unused lines of code in user.js (var passwordStrength and var passwordResult defined but never used), and a few coding style issues in user.js. I have included those fixes in the patch.

Patch follows ...

CommentFileSizeAuthor
#1 788166-multiple_password_confirms.patch4.12 KBtr

Comments

tr’s picture

Status: Active » Needs review
StatusFileSize
new4.12 KB

and the patch:

tr’s picture

Bump. Looking for a review ...

tr’s picture

Issue tags: +D7 Form API challenge

Tagging...

tomdavidson’s picture

Status: Needs review » Reviewed & tested by the community

In review of Patch #1:
Code passes jslint.com and Dmitrig01 (thanks).
There are just enough comments to understand.
Patch solves the behavior described and was verified by additional password_confirm elements in user.module, then visually observing editing the user account.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

gábor hojtsy’s picture

I've submitted a *very* similar patch before at #688066: Password strength checker can only be used once which got little attention unfortunately. Marking that as duplicate.

sun’s picture

Component: forms system » user.module
Status: Fixed » Needs work
Issue tags: -D7 Form API challenge +Needs tests
+++ modules/user/user.module	3 May 2010 05:03:19 -0000
@@ -3250,7 +3250,12 @@ function user_form_process_password_conf
+  // Ensure settings are only added once per page.
+  static $already_added = FALSE;
+  if (!$already_added) {
+    $already_added = TRUE;

This static is very likely incompatible with testing.

That said, a bug fix without test?

Powered by Dreditor.

tomdavidson’s picture

@sun do you mind elaborating a bit more to a newb?

"Testing" is the Drupal auto QA?

Tor Arne Thune’s picture

Title: password_confirm element breaks if there is more than 1 on a page » (Tests needed) password_confirm element breaks if there is more than 1 on a page
Version: 7.x-dev » 8.x-dev
Category: bug » task
Issue tags: +Needs backport to D7

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • Dries committed 7c2bcff on 8.3.x
    - Patch #788166 by TR: password_confirm() element breaks if there is...

  • Dries committed 7c2bcff on 8.3.x
    - Patch #788166 by TR: password_confirm() element breaks if there is...

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • Dries committed 7c2bcff on 8.4.x
    - Patch #788166 by TR: password_confirm() element breaks if there is...

  • Dries committed 7c2bcff on 8.4.x
    - Patch #788166 by TR: password_confirm() element breaks if there is...

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

  • Dries committed 7c2bcff on 9.1.x
    - Patch #788166 by TR: password_confirm() element breaks if there is...

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone’s picture

Status: Needs work » Fixed

Work done by longwave using an LLM that identified this as a duplicate of #2862278: Add tests that multiple password_confirm fields work on the same page and suggested closing this one.

In this case I am going to close this older issue. I am going to close it as fixed on 7.x which was when the commit was made.

The remaining work, adding a test, can be done in the newer issue.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

quietone’s picture

Version: main » 7.x-dev

Status: Fixed » Closed (fixed)

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