Core\Ldap\Sid::parse
Core\Ldap\Sid::parse(string $text): Core\Ldap\SidCore\Ldap\Sid::parse( string $text, ): Core\Ldap\Sid
Reads SID text, such as S-1-5-32-544, and returns a Core\Ldap\Sid. A SID (security identifier) is the number Windows uses for a user, a group or a computer.
Use it for a SID that you wrote yourself or that a user typed. Then you can compare it with the SIDs a directory returns, or read its parts with domain and rid.
Good to know: the text starts with S-1-, then the authority, then 1 to 15 numbers. Each number is at most 4294967295. Text that is not a SID throws a LogicError, and its message says which part is wrong.
Parameters
$textstringThe text. It starts withS-1-, then the authority, then 1 to 15 numbers, all joined by-.
Return value
Returns Core\Ldap\Sid. A Core\Ldap\Sid.
Errors
LogicErrorThe text is not a SID. The message says which part is wrong.
Examples
Read a sid
<?nvs// Shows how to read SID text and get its last number.
var $admins = Core\Ldap\Sid::parse('S-1-5-32-544');// This prints S-1-5-32-544 and then 544.echo $admins->toString(), "\n";echo $admins->rid(), "\n";S-1-5-32-544544Check the text
<?nvs// Shows how to check text that should be a SID.
array<string> $texts = ['S-1-5-32-544', 'S-1-5-admins', 'S-1-5'];// The first text is a SID. The other two throw a `LogicError`.foreach ($texts as string $text) { try { echo Core\Ldap\Sid::parse($text)->toString(), " is a SID\n"; } catch (LogicError $refusal) { echo $text, " is not a SID\n"; }}S-1-5-32-544 is a SIDS-1-5-admins is not a SIDS-1-5 is not a SIDCompare two sids
<?nvs// Shows that two ways to write the same SID give the same SID.
// The authority may be written in hex with `0x`. Both texts have authority 5.var $short = Core\Ldap\Sid::parse('S-1-5-18');var $long = Core\Ldap\Sid::parse('S-1-0x000000000005-18');// The bytes are the same, so this prints same.echo $short->bytes() == $long->bytes() ? 'same' : 'different', "\n";same