public static function GenerateSecurePassword($length = 16, array $sets = null, array $enabledSets = null)
{
static $predefinedSets = ['l' => 'abcdefghjkmnpqrstuvwxyz', 'u' => 'ABCDEFGHJKMNPQRSTUVWXYZ', 'd' => '1234567890', 's' => '!@#$%&*?'];
$sets = empty($sets) ? $predefinedSets : array_merge($predefinedSets, $sets);
if (!empty($enabledSets)) {
$sets = array_intersect_key($sets, array_flip($enabledSets));
}
$password = '';
foreach ($sets as $set) {
$password .= $set[mt_rand(0, strlen($set) - 1)];
}
$all = implode($sets);
$setLength = strlen($all) - 1;
$length -= count($sets);
for ($i = 0; $i < $length; $i++) {
$password .= $all[mt_rand(0, $setLength)];
}
return str_shuffle($password);
}