Core\Ldap\Ad\AccountFlags::hasNonExpiringPassword
$accountFlags->hasNonExpiringPassword(): boolChecks if the password of an account never expires. The result is true or false.
Active Directory normally makes a user change the password after some time. The domain sets this time, for example six weeks. When this flag is set, the password of the account does not expire. Administrators often set it for service accounts, which programs use to log in.
hasNonExpiringPassword reads the bit 0x10000 of userAccountControl. A normal account with this flag is 66048.
Return value
Returns bool. true when the bit is set, and false when it is not.
Changelog
| Version | Change |
|---|---|
0.0.6 | Every Core\Ldap\Ad\AccountFlags method that checks a flag now starts with is, has, allows or uses, for example isDisabled() and hasNonExpiringPassword(). The field trustedToAuthForDelegation of with() is now trustedToAuthenticateForDelegation. |
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 service account
<?nvs// Shows that `hasNonExpiringPassword` returns `true` for an account whose password does not expire.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $flags = $corp->read('CN=Reader,OU=Company,DC=example,DC=test', { select: ['userAccountControl'] })?->accountFlags();
if ($flags != null) { // This prints `never expires: true`. echo 'never expires: ', $flags->hasNonExpiringPassword() ? 'true' : 'false', "\n";}never expires: trueFind passwords that never expire
<?nvs// Shows how to find the accounts whose password never expires, for example to review them.// 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 $account) { var $flags = $account->accountFlags(); if ($flags != null && $flags->hasNonExpiringPassword()) { $names[] = $account->dn()->rdnValue(); }}
// The server sends entries in no fixed order, so the names are sorted.// This prints `Ben Kohl` and `Reader`.foreach (Core\Arr::sort($names) as tainted string $name) { echo $name, "\n";}Ben KohlReaderLet it expire again
<?nvs// Shows how to get the flags of an account whose password should expire again.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');var $flags = $corp->read('CN=Ben Kohl,OU=Company,DC=example,DC=test', { select: ['userAccountControl'] })?->accountFlags();
if ($flags != null) { var $changed = $flags->with({ passwordNeverExpires: false });
// This prints `66048 never expires` and then `512 expires`. echo $flags->bits(), $flags->hasNonExpiringPassword() ? ' never expires' : ' expires', "\n"; echo $changed->bits(), $changed->hasNonExpiringPassword() ? ' never expires' : ' expires', "\n";}66048 never expires512 expires