1.20.x user.module user_login($form, &$form_state)

Form builder; the main user login form.

Related topics

File

modules/user/user.module, line 1705
Enables the user registration and login system.

Code

function user_login($form, &$form_state) {
  global $user;

  // If we are already logged on, go to the user page instead.
  if ($user->uid) {
    backdrop_goto('user/' . $user->uid);
  }

  backdrop_set_title(t('Log in'));

  // Display login form:
  $credentials = config_get('system.core', 'user_login_method');
  $form['name'] = array('#type' => 'textfield',
    '#title' => $credentials === USER_LOGIN_EMAIL_ONLY ? t('Email address') : ($credentials === USER_LOGIN_USERNAME_OR_EMAIL ? t('Username or email') : t('Username')),
    '#maxlength' => $credentials === USER_LOGIN_USERNAME_ONLY ? USERNAME_MAX_LENGTH : EMAIL_MAX_LENGTH,
    '#size' => 60,
    '#required' => TRUE,
    '#attributes' => array(
      'autofocus' => 'autofocus',
    ),
  );

  $form['pass'] = array(
    '#type' => 'password',
    '#title' => t('Password'),
    '#required' => TRUE,
    '#password_toggle' => TRUE,
  );
  $form['#validate'] = user_login_default_validators();
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Log in'));

  return $form;
}