You are here

function ldap_password_modify in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 7.2 ldap_servers/ldap_servers.functions.inc \ldap_password_modify()
  2. 7 ldap_servers/ldap_servers.functions.inc \ldap_password_modify()

Modify a password

File

ldap_servers/ldap_servers.functions.inc, line 28
collection of functions that don't belong in server object

Code

function ldap_password_modify($userdn, $new_password, $ldap_server) {
  $new_password = "\"" . $new_password . "\"";
  $len = drupal_strlen($new_password);
  $new_pass = NULL;
  for ($i = 0; $i < $len; $i++) {
    $new_pass .= "{$new_password[$i]}\0";
  }
  $status = ldap_mod_replace($ldap_server->connection, $userdn, array(
    'unicodePwd' => $new_pass,
  ));
  if (!$status) {
    watchdog('ldap_servers', 'Error: password_modify() failed to modify ldap password w/ base DN "!dn"', array(
      '!dn' => $userdn,
    ), WATCHDOG_ERROR);
  }
  return $status;
}