You are here

function password_confirm_validate in Drupal 7

Same name and namespace in other branches
  1. 4 includes/form.inc \password_confirm_validate()
  2. 5 includes/form.inc \password_confirm_validate()
  3. 6 includes/form.inc \password_confirm_validate()

Validates a password_confirm element.

Related topics

1 string reference to 'password_confirm_validate'
form_process_password_confirm in includes/form.inc
Expand a password_confirm field into two text boxes.

File

includes/form.inc, line 3040
Functions for form and batch generation and processing.

Code

function password_confirm_validate($element, &$element_state) {
  $pass1 = trim($element['pass1']['#value']);
  $pass2 = trim($element['pass2']['#value']);
  if (strlen($pass1) > 0 || strlen($pass2) > 0) {
    if (strcmp($pass1, $pass2)) {
      form_error($element, t('The specified passwords do not match.'));
    }
  }
  elseif ($element['#required'] && !empty($element_state['input'])) {
    form_error($element, t('Password field is required.'));
  }

  // Password field must be converted from a two-element array into a single
  // string regardless of validation results.
  form_set_value($element['pass1'], NULL, $element_state);
  form_set_value($element['pass2'], NULL, $element_state);
  form_set_value($element, $pass1, $element_state);
  return $element;
}