Core\Ldap\Ad\AccountFlags::allowsReversibleEncryption
$accountFlags->allowsReversibleEncryption(): boolChecks if the password of an account is stored with an encryption that can be reversed. The result is true or false.
Active Directory normally stores only a hash of a password, and a hash cannot be turned back into the password. When this flag is set, the server stores the password in a form it can decrypt. Some old programs need this. It is less safe, so most accounts do not have this flag.
allowsReversibleEncryption reads the bit 0x80 of userAccountControl. A normal account with this flag is 640.
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"]An account with a hashed password
<?nvs// Shows that `allowsReversibleEncryption` returns `false` for an account whose password is stored as a hash.// 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 `reversible: false`. echo 'reversible: ', $flags->allowsReversibleEncryption() ? 'true' : 'false', "\n";}reversible: falseCount reversible passwords
<?nvs// Shows how to count the accounts whose password the server can decrypt.// 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'] },);
uint $count = 0;uint $all = 0;foreach ($found as Core\Ldap\Entry $account) { var $flags = $account->accountFlags(); if ($flags != null) { $all = $all + 1; if ($flags->allowsReversibleEncryption()) { $count = $count + 1; } }}
// No account in this directory has this flag. This prints `0 of 5`.echo $count, ' of ', $all, "\n";0 of 5Set it on a copy
<?nvs// Shows how `allowsReversibleEncryption` and the number change on a copy made with `with`.// 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) { var $changed = $flags->with({ reversibleEncryption: true });
// This prints `512 false` and then `640 true`. echo $flags->bits(), $flags->allowsReversibleEncryption() ? ' true' : ' false', "\n"; echo $changed->bits(), $changed->allowsReversibleEncryption() ? ' true' : ' false', "\n";}512 false640 true