You are here

function ldap_authentication_show_password_field in Lightweight Directory Access Protocol (LDAP) 8.4

Should the password field be shown?

Parameters

\Drupal\user\UserInterface|\Drupal\Core\Session\AccountProxyInterface $user: User account.

Return value

bool Password status.

1 call to ldap_authentication_show_password_field()
ldap_authentication_form_user_form_alter in ldap_authentication/ldap_authentication.module
Implements hook_form_FORM_ID_alter().

File

ldap_authentication/ldap_authentication.module, line 170

Code

function ldap_authentication_show_password_field($user = NULL) : bool {
  if (!$user) {
    $user = \Drupal::currentUser();
  }
  if ($user
    ->hasPermission('administer users')) {
    return TRUE;
  }

  // Hide only if LDAP authenticated and updating password is not allowed.

  /** @var \Drupal\externalauth\Authmap $authmap */
  $authmap = \Drupal::service('externalauth.authmap');
  $authname = $authmap
    ->get($user
    ->id(), 'ldap_user');
  if ($authname) {
    $password_option = \Drupal::config('ldap_authentication.settings')
      ->get('passwordOption');
    return $password_option === 'allow';
  }

  // Default to showing.
  return TRUE;
}