I'm looking for a way to validate if an inserted Object SID from Active Directory is valid, is this possible using preg_match()
or preg_match_all()
?
I've looked online for a regex for this validation but I couldn't find anything.
Example:
$sid = 'S-1-5-21-1220945662-1202665555-839525555-5555';
if ($validator->validateSid($sid)) {
// SID is valid!
}
I'm not skilled in writing regex's, so if anyone has absolutely any input, please let me know, thanks!
EDIT: For anyone looking for the code with the regex below:
preg_match("/^S-1-[0-5]-\d{2}-\d{10}-\d{10}-\d{9}-[1-9]\d{3}/", $search, $matches);
// Returns
array(
0 => S-1-5-21-1220945662-1202665555-839525555-5555
)
Or for a more lenient pattern:
preg_match("/S-1-5-21-\d+-\d+\-\d+\-\d+/", $sid, $matches);
// Returns
array(
0 => S-1-5-21-1220945662-1202665555-839525555-5555
)