On the user edit page (and presumably on other pages with password_confirm fields), if a user enters a password only in the "Confirm password" field (ie, the 2nd field), the form validates and returns "The changes have been saved." However, the password hasn't been changed. The validation in the form.inc password_confirm_validate function only runs if the first password isn't blank.

I've done some testing and the same issue exists in D5, D6, and D7.

I'm attaching a small patch that runs the validation if either the first or second password field are not blank.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

c960657’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

This is a stupid bug to have. Let's get some tests for this.

ugerhard’s picture

FileSize
910 bytes

First a quick reroll. We will try to write a test for this at the Paris code sprint today

ugerhard’s picture

Status: Needs work » Needs review
FileSize
2.32 KB

Now with test

attiks’s picture

Patch applies fine and fixed the problem
+1

Status: Needs review » Needs work

The last submitted patch failed testing.

Jody Lynn’s picture

Status: Needs work » Needs review
FileSize
2.8 KB

I adjusted the tests a bit and rerolled.

Matt V.’s picture

The tests look good to me, with the exception of the description for the last test. Does "Save user password with mismatched type in password confirm" really describe what is happening there? It looks to me like it's setting matching passwords, but it says "mismatched" in the description.

lcool’s picture

Issue tags: -Needs tests

#7: password.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Needs tests

The last submitted patch, password.patch, failed testing.

Jody Lynn’s picture

I'm rerolling

Jody Lynn’s picture

Component: forms system » user system
Status: Needs work » Needs review
FileSize
2.71 KB

Patch rerolled. I removed the part of the test with the wording criticized in #8 (the part showing that matching passwords do work) because it now seemed to be redundant with existing tests.

domthinks’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed and testing with drupal 7.x-dev and worked as expected. The patch checks both password fields and if the 'confirm password' field is empty it returns "The specified passwords do not match."

stupiddingo’s picture

Works when one of the two is null, but exhibits some odd behavior from a usability standpoint when both are null.

Three possibilities:

If "confirm password" is null:

Error Message
----------------
The specified passwords do not match.
Your current password is missing or incorrect; it's required to change the Password.

If "password" is null:
Error Message
----------------
The specified passwords do not match.

Both Null:
Error Message
----------------
The changes have been saved.

>>> This makes sense in a way since one could change the their timezone and would not need to enter their passwords. But oddly, (is this is separate issue?) it returns The changes have been saved. when no changes are made and the form is posted (technically this may be true, but it's a little odd from a usability standpoint).

Dries’s picture

Status: Reviewed & tested by the community » Needs work

Committed #12 to CVS HEAD, but we might want to tweak things some more based on #14.

chriso’s picture

Subscribing

Tsalop’s picture

Here is a quick fix for #14 issue based on Jody Lynns patch:

  $pass1 = trim($element['pass1']['#value']); //Get password
  $pass2 = trim($element['pass2']['#value']); //Get confirmation

//Only match if both fields filled:
  if(!empty($pass1 || !empty($pass2)){
     if(strcmp($pass1, $pass2)){
        form_error($element, t((empty($pass1) && !empty($pass2))?'Your new password is missing or incorrect; it\'s required to change the Password.':'The specified passwords do not match.'));        
     }
//Check wether the password is required input: 
  }elseif($element['#required'] && !empty($element_state['input'])) {
     form_error($element, t('Password field is required.'));
  }
 

I'll post patch after finding a good solution for that "The changes have been saved" - message
even if no changes have been...

Tsalop’s picture

The solution mentioned in my previous post can be found from this patch.

Gaelan’s picture

Issue tags: +Needs reroll

Needs a reroll because everything moved to core/* in D8.

Gaelan’s picture

Issue tags: -Needs reroll

Oh. This is 7. Never mind.

rkjha’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

#12: password.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Needs tests

The last submitted patch, password.patch, failed testing.

rkjha’s picture

To the best of my understanding, the test cases for this issue and for changing password or other user details are complete. I can't think of anything else that should be included except for the case when the message "The changes have been saved" is displayed even when there have been no changes. Any suggestion is welcome.

rkjha’s picture

All the changes suggested in #14 have already been committed(commit no 66d75d16fcc1e531811fb3bcf32a2f4318c01588). And the tests for the same already exist. The only thing that seems to remain is finding a solution for "The changes have been saved" message as mentioned in #14. But that appears more to be a feature request than a bug an this is apparently "impossible" to fix. I therefore suggest to close this issue as it has been open for quite a long without really making much sense.

star-szr’s picture

@rkjha and I talked about this issue in IRC today.

As far as we can tell from looking at this issue and performing manual tests of the user edit form, the only change (at least for D7/D8) that is mentioned in #14 is that when no changes are made to the user profile, the message "The changes have been saved." should not be displayed.

We agreed that #14 seems like more of a feature request, and that it would need to apply on a higher level so that for example updating a node without changing any fields would not say "[node:title] has been updated."

So unless we're both missing something, I think we can close this issue as fixed since the main issue was addressed with the commit in #12 and the response to the request in #14 would likely be "closed (won't fix)" or maybe even "closed (works as designed)".

dman’s picture

Status: Needs work » Closed (works as designed)

I can't see any reason to keep this open now, no.
I'll bump it to 'as designed' as this original issue has been fixed enough now.