You are here

protected function LdapUserManager::convertPasswordForActiveDirectoryUnicodePwd in Lightweight Directory Access Protocol (LDAP) 8.4

Convert password to format required by Active Directory.

For the purpose of changing or setting the password. Note that AD needs the field to be called unicodePwd (as opposed to userPassword).

Parameters

string|array $password: The password that is being formatted for Active Directory unicodePwd field.

Return value

string|array $password surrounded with quotes and in UTF-16LE encoding

2 calls to LdapUserManager::convertPasswordForActiveDirectoryUnicodePwd()
LdapUserManager::applyModificationsToEntry in ldap_servers/src/LdapUserManager.php
Apply modifications to entry.
LdapUserManager::createLdapEntry in ldap_servers/src/LdapUserManager.php
Create LDAP User entry.

File

ldap_servers/src/LdapUserManager.php, line 133

Class

LdapUserManager
LDAP User Manager.

Namespace

Drupal\ldap_servers

Code

protected function convertPasswordForActiveDirectoryUnicodePwd($password) {

  // This function can be called with $attributes['unicodePwd'] as an array.
  if (!is_array($password)) {
    return mb_convert_encoding(sprintf('"%s"', $password), 'UTF-16LE');
  }

  // Presumably there is no use case for there being more than one password
  // in the $attributes array, hence it will be at index 0, and we return in
  // kind.
  return [
    mb_convert_encoding(sprintf('"%s"', $password[0]), 'UTF-16LE'),
  ];
}