diff --git a/includes/form.inc b/includes/form.inc index 826b677..2196543 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -2863,10 +2863,14 @@ function form_process_password_confirm($element) { function password_confirm_validate($element, &$element_state) { $pass1 = trim($element['pass1']['#value']); $pass2 = trim($element['pass2']['#value']); - if (!empty($pass1) || !empty($pass2)) { - if (strcmp($pass1, $pass2)) { - form_error($element, t('The specified passwords do not match.')); - } +//Check that the main password is long enough (4) + if(strlen($pass1) < 4) + form_error($element, t('Password must be atleast 4 characters long.')); +//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 passowrd is missing or incorrect; it\'s required to change the Password.':'The specified passwords do not match.')); + } } elseif ($element['#required'] && !empty($element_state['input'])) { form_error($element, t('Password field is required.')); diff --git a/modules/user/user.test b/modules/user/user.test index 92af9fa..ee168c7 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -1791,13 +1791,45 @@ class UserEditTestCase extends DrupalWebTestCase { $edit['pass[pass1]'] = ''; $edit['pass[pass2]'] = $this->randomName(); $this->drupalPost("user/$user1->uid/edit", $edit, t('Save')); - $this->assertText(t("The specified passwords do not match."), t('Typing mismatched passwords displays an error message.')); + $this->assertText(t("The new password is missing."), t('Typing mismatched passwords displays an error message.')); $edit['pass[pass1]'] = $this->randomName(); $edit['pass[pass2]'] = ''; $this->drupalPost("user/$user1->uid/edit", $edit, t('Save')); + $this->assertText(t("The password needs to be confirmed."), t('Typing mismatched passwords displays an error message.')); + + // Test that case insensitive passwords are not allowed: + $edit = array(); + $edit['pass[pass1]'] = 'PassWorD'; + $edit['pass[pass2]'] = 'password'; + $this->drupalPost("user/$user1->uid/edit", $edit, t('Save')); $this->assertText(t("The specified passwords do not match."), t('Typing mismatched passwords displays an error message.')); + // Test that the password is long enough: + $edit = array(); + $edit['pass[pass1]'] = 'p'; + $edit['pass[pass2]'] = 'p'; + $this->drupalPost("user/$user1->uid/edit", $edit, t('Save')); + $this->assertText(t("The password is too short."), t('Typing too short passwords displays an error message.')); + + $edit = array(); + $edit['pass[pass1]'] = 'pa'; + $edit['pass[pass2]'] = 'pa'; + $this->drupalPost("user/$user1->uid/edit", $edit, t('Save')); + $this->assertText(t("The password is too short."), t('Typing too short passwords displays an error message.')); + + $edit = array(); + $edit['pass[pass1]'] = 'pas'; + $edit['pass[pass2]'] = 'pas'; + $this->drupalPost("user/$user1->uid/edit", $edit, t('Save')); + $this->assertText(t("The password is too short."), t('Typing too short passwords displays an error message.')); + + $edit = array(); + $edit['pass[pass1]'] = 'pass'; + $edit['pass[pass2]'] = 'pass'; + $this->drupalPost("user/$user1->uid/edit", $edit, t('Save')); + $this->assertText(t("The password is too short."), t('Typing too short passwords displays an error message.')); + // Test that the error message appears when attempting to change the mail or // pass without the current password. $edit = array();