You are here

private function LdapEntryProvisionSubscriber::fetchDrupalAccountPassword in Lightweight Directory Access Protocol (LDAP) 8.4

Fetch the password token.

Parameters

string $attribute_name: Field variant.

Return value

string Password.

1 call to LdapEntryProvisionSubscriber::fetchDrupalAccountPassword()
LdapEntryProvisionSubscriber::fetchDrupalAccountAttribute in ldap_user/src/EventSubscriber/LdapEntryProvisionSubscriber.php
Fetch a single token.

File

ldap_user/src/EventSubscriber/LdapEntryProvisionSubscriber.php, line 377

Class

LdapEntryProvisionSubscriber
Event subscribers for creating and updating LDAP entries.

Namespace

Drupal\ldap_user\EventSubscriber

Code

private function fetchDrupalAccountPassword(string $attribute_name) : string {
  $value = '';
  switch ($attribute_name) {
    case 'user':
    case 'user-only':
      $value = CredentialsStorage::getPassword();
      break;
    case 'user-random':
      $pwd = CredentialsStorage::getPassword();
      if (version_compare(\Drupal::VERSION, '9.1', '>=')) {
        $generated = \Drupal::service('password_generator')
          ->generate();
      }
      else {
        $generated = user_password();
      }
      $value = $pwd ?: $generated;
      break;
    case 'random':
      if (version_compare(\Drupal::VERSION, '9.1', '>=')) {
        $value = \Drupal::service('password_generator')
          ->generate();
      }
      else {
        $value = user_password();
      }
      break;
  }
  return $value;
}