1 user.module | user_form_process_password($element, $form_state = array()) |
Form element process handler for client-side password hide/show and strength.
Parameters
array $element: The form element to process.
array $form_state: The $form_state array of the form this element belongs to.
File
- core/
modules/ user/ user.module, line 2971 - Enables the user registration and login system.
Code
function user_form_process_password($element, $form_state = array()) {
global $user;
$config = config('system.core');
if ($element['#password_strength']) {
if (isset($form_state['user']) && is_a($form_state['user'], 'User')) {
// Existing account, not the current user if an admin edits an account.
$username = $form_state['user']->name;
$email = $form_state['user']->mail;
}
else {
// The AnonymousUser object has no mail property, and name is NULL.
// The User object has both mail and name set.
$username = (isset($user->name) ? $user->name : '');
$email = (isset($user->mail) ? $user->mail : '');
}
$strength_settings = array(
'scores' => array(
'weak' => USER_PASSWORD_STRENGTH_WEAK,
'fair' => USER_PASSWORD_STRENGTH_FAIR,
'good' => USER_PASSWORD_STRENGTH_GOOD,
'strong' => USER_PASSWORD_STRENGTH_STRONG,
),
'labels' => array(
'strengthTitle' => t('Password strength: '),
'weak' => t('weak'),
'fair' => t('fair'),
'good' => t('good'),
'strong' => t('excellent'),
),
'data' => array(
'username' => $username,
'email' => $email,
),
'config' => array(
'strengthModifier' => USER_PASSWORD_STRENGTH_MODIFIER,
),
);
$element['#attributes']['data-password-strength'] = backdrop_json_encode($strength_settings, FALSE);
}
if ($element['#password_toggle']) {
$toggle_settings = array(
'toggleShowTitle' => t('Show password'),
'toggleHideTitle' => t('Hide password'),
'toggleDefault' => $element['#password_shown'] ? 'show' : 'hide',
);
$element['#attributes']['data-password-toggle'] = backdrop_json_encode($toggle_settings, FALSE);
}
if ($element['#password_strength'] || $element['#password_toggle']) {
$element['#attached']['js'][] = backdrop_get_path('module', 'user') . '/js/user.js';
}
return $element;
}