function user_validate_current_pass in Drupal 7
Form validation handler for the current password on the user_account_form().
See also
2 string references to 'user_validate_current_pass'
- user_account_form in modules/
user/ user.module - Helper function to add default user account fields to user registration and edit form.
- user_form_test_current_password in modules/
user/ tests/ user_form_test.module - A test form for user_validate_current_pass().
File
- modules/
user/ user.module, line 1228 - Enables the user registration and login system.
Code
function user_validate_current_pass(&$form, &$form_state) {
$account = $form['#user'];
foreach ($form_state['values']['current_pass_required_values'] as $key => $name) {
// This validation only works for required textfields (like mail) or
// form values like password_confirm that have their own validation
// that prevent them from being empty if they are changed.
if (strlen(trim($form_state['values'][$key])) > 0 && $form_state['values'][$key] != $account->{$key}) {
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
$current_pass_failed = strlen(trim($form_state['values']['current_pass'])) == 0 || !user_check_password($form_state['values']['current_pass'], $account);
if ($current_pass_failed) {
form_set_error('current_pass', t("Your current password is missing or incorrect; it's required to change the %name.", array(
'%name' => $name,
)));
form_set_error($key);
}
// We only need to check the password once.
break;
}
}
}