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 ...
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 788166-multiple_password_confirms.patch | 4.12 KB | tr |
Comments
Comment #1
tr commentedand the patch:
Comment #2
tr commentedBump. Looking for a review ...
Comment #3
tr commentedTagging...
Comment #4
tomdavidson commentedIn 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.
Comment #5
dries commentedCommitted to CVS HEAD. Thanks.
Comment #6
gábor hojtsyI'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.
Comment #7
sunThis static is very likely incompatible with testing.
That said, a bug fix without test?
Powered by Dreditor.
Comment #8
tomdavidson commented@sun do you mind elaborating a bit more to a newb?
"Testing" is the Drupal auto QA?
Comment #9
Tor Arne Thune commentedComment #29
quietone commentedWork 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.
Comment #31
quietone commented