PHP 隨機亂數密碼產生幾種方式
// 產生包含英文和數字的隨機密碼
while (true) {
$password = Str::random($length);
if (! preg_match('/[a-zA-Z]/', $password)) {
continue;
}
if (! preg_match('/\d/', $password)) {
continue;
}
return $password;
}
$bytes = openssl_random_pseudo_bytes(4);
$pass = bin2hex($bytes);
$comb = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$shfl = str_shuffle($comb);
$pwd = substr($shfl,0,8);