Skip to content

Core\Ldap\Ad\AccountFlags::isLockedOut

$accountFlags->isLockedOut(): bool

Checks if an account is locked out. The result is true or false.

Active Directory locks an account after too many wrong passwords. Nobody can log in with it until the lockout time ends or an administrator unlocks it.

Active Directory computes this flag. It does not store it in userAccountControl. A search that selects userAccountControl also reads msDS-User-Account-Control-Computed, and isLockedOut reads the bit 0x10 from there. So bits never includes it, and with cannot set or clear it.

Return value

Returns bool. true when the bit is set, and false when it is not.

Changelog

VersionChange
0.0.6Every 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.

nvs.toml
# 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"]

An account that is not locked

<?nvs
// Shows that `isLockedOut` returns `false` for an account that nobody has locked by typing wrong passwords.
// requires: samba-ad
var $corp = Core\Ldap::connect('corp');
var $flags = $corp->read('CN=Anna Berg,OU=Company,DC=example,DC=test', { select: ['userAccountControl'] })?->accountFlags();
if ($flags != null) {
// This prints `locked out: false`.
echo 'locked out: ', $flags->isLockedOut() ? 'true' : 'false', "\n";
}
Output
locked out: false

Why a login fails

<?nvs
// Shows how to give a person a clear reason why they cannot log in.
// requires: samba-ad
var $corp = Core\Ldap::connect('corp');
array<string> $dns = [
'CN=Anna Berg,OU=Company,DC=example,DC=test',
'CN=Dora Lind,OU=Company,DC=example,DC=test',
];
foreach ($dns as string $dn) {
var $person = $corp->read($dn, { select: ['userAccountControl'] });
var $flags = $person?->accountFlags();
if ($person == null || $flags == null) {
continue;
}
string $reason = 'can log in';
if ($flags->isLockedOut()) {
$reason = 'locked out, try again later';
}
if ($flags->isDisabled()) {
$reason = 'disabled';
}
// This prints `Anna Berg: can log in` and `Dora Lind: disabled`.
echo $person->dn()->rdnValue(), ': ', $reason, "\n";
}
Output
Anna Berg: can log in
Dora Lind: disabled

Not part of bits

<?nvs
// Shows that `isLockedOut` is not part of the number `bits` returns.
// requires: samba-ad
var $corp = Core\Ldap::connect('corp');
var $flags = $corp->read('CN=Anna Berg,OU=Company,DC=example,DC=test', { select: ['userAccountControl'] })?->accountFlags();
if ($flags != null) {
// The bit `0x10` is `16`. This prints `bit in bits: no`.
echo 'bit in bits: ', $flags->bits() % 32 >= 16 ? 'yes' : 'no', "\n";
// A copy made with `with` keeps the value. This prints `copy locked out: false`.
echo 'copy locked out: ', $flags->with({ disabled: true })->isLockedOut() ? 'true' : 'false', "\n";
}
Output
bit in bits: no
copy locked out: false