Skip to content

Commit

Permalink
Function to modify password
Browse files Browse the repository at this point in the history
  • Loading branch information
coudot committed Jul 24, 2024
1 parent 9fdd564 commit 696a407
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Ltb/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ public function getPasswordMaxAge($ldap, $dn, $config) : ?int;
* Date when password will be expired
*/
public function getPasswordExpirationDate($ldap, $dn, $config) : ?DateTime;

/*
* Modify the password
*/
public function modifyPassword($ldap, $dn, $password, $forceReset) : bool;
}
20 changes: 20 additions & 0 deletions src/Ltb/Directory/ActiveDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,24 @@ public function getPasswordMaxAge($ldap, $dn, $config) : ?int {
return $config['pwdMaxAge'];
}

public function modifyPassword($ldap, $dn, $password, $forceReset) : bool {

$adPassword = \Ltb\Password::make_ad_password($password);
$changes = array('unicodePwd' => $adPassword);

if ($forceReset) {
$changes['pwdLastSet'] = 0;
}

$update = \Ltb\PhpLDAP::ldap_mod_replace($ldap, $dn, $changes);
$errno = ldap_errno($ldap);

if ($errno) {
error_log("LDAP - Modify password error $errno (".ldap_error($ldap).")");
return false;
} else {
return true;
}

}
}
19 changes: 19 additions & 0 deletions src/Ltb/Directory/OpenLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,23 @@ public function getPasswordMaxAge($ldap, $dn, $config) : ?int {

return $pwdMaxAge;
}

public function modifyPassword($ldap, $dn, $password, $forceReset) : bool {

$changes = array('userPassword' => $password);

if ($forceReset) {
$changes['pwdReset'] = 'TRUE';
}

$update = \Ltb\PhpLDAP::ldap_mod_replace($ldap, $dn, $changes);
$errno = ldap_errno($ldap);

if ($errno) {
error_log("LDAP - Modify password error $errno (".ldap_error($ldap).")");
return false;
} else {
return true;
}
}
}

0 comments on commit 696a407

Please sign in to comment.