安全警告
:rand()不是加密安全的伪随机数生成器。寻找其他地方以在PHP中生成加密安全的伪随机字符串。
试试这个(使用
strlen代替
count,因为
count在字符串上总是
1):
function randomPassword() { $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; $pass = array(); //remember to declare $pass as an array $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache for ($i = 0; $i < 8; $i++) { $n = rand(0, $alphaLength); $pass[] = $alphabet[$n]; } return implode($pass); //turn the array into a string}


