Core\Ldap\Ad\AccountFlags::mustChangePassword
$accountFlags->mustChangePassword(): boolChecks if the user must change the password at the next login. The result is true or false.
Active Directory has no bit in userAccountControl for this. It stores 0 in pwdLastSet instead. mustChangePassword returns true when pwdLastSet is 0. It returns false when pwdLastSet has another value or the entry has no pwdLastSet.
You do not need to select pwdLastSet yourself. A search that selects userAccountControl also reads pwdLastSet. with keeps this value, because it only changes the bits of userAccountControl.
Return value
Returns bool. true when pwdLastSet is 0, and false when it is not or the entry has no pwdLastSet.
Examples
The examples below run with this configuration file.
# These examples use the LDAP directory server on this computer at port 16636.# `tls_ca_file` is the certificate that the server's certificate is checked against.[ldap.corp]url = "ldaps://127.0.0.1:16636"base = "DC=example,DC=test"user = "CN=Reader,OU=Company,DC=example,DC=test"password = "Novis-reader-1"tls_ca_file = "../../../../../tests/db/ca.crt"timeout = "5s"
# The program may open the `corp` directory.[capabilities.ldap]connect = ["corp"]A new password is due
<?nvs// Shows that `mustChangePassword` returns `true` for a user who must set a new password.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $flags = $corp->read('CN=Carla Diaz,OU=Company,DC=example,DC=test', { select: ['userAccountControl'] })?->accountFlags();
if ($flags != null) { // Carla Diaz has `pwdLastSet` set to `0`. This prints `must change: true`. echo 'must change: ', $flags->mustChangePassword() ? 'true' : 'false', "\n";}must change: trueWho must change it
<?nvs// Shows how to find the people who must change their password at the next login.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $found = $corp->search( Core\Ldap\Filter::equals('objectClass', 'user'), { base: 'OU=Company,DC=example,DC=test', select: ['userAccountControl'] },);
array<tainted string> $names = [];foreach ($found as Core\Ldap\Entry $person) { var $flags = $person->accountFlags(); if ($flags != null && $flags->mustChangePassword()) { $names[] = $person->dn()->rdnValue(); }}
// The server sends entries in no fixed order, so the names are sorted.// This prints `Carla Diaz`.foreach (Core\Arr::sort($names) as tainted string $name) { echo $name, "\n";}Carla DiazA copy keeps it
<?nvs// Shows that a copy made with `with` keeps `mustChangePassword`, because it is not a bit of `userAccountControl`.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $flags = $corp->read('CN=Carla Diaz,OU=Company,DC=example,DC=test', { select: ['userAccountControl'] })?->accountFlags();
if ($flags != null) { var $disabled = $flags->with({ disabled: true });
// This prints `disabled: true, must change: true`. echo 'disabled: ', $disabled->isDisabled() ? 'true' : 'false'; echo ', must change: ', $disabled->mustChangePassword() ? 'true' : 'false', "\n";}disabled: true, must change: true