随机密码php,PHP会生成随机密码
我已經把這個使用了單詞列表的小腳本放在一起來生成一個可讀的密碼。
代碼的第一部分通過生成單詞和數字而正常工作。問題在于最后的符號似乎每隔一段時間都會有效。
function random_readable_pwd($length=10){
// the wordlist from which the password gets generated
// (change them as you like)
$words = 'AbbyMallard,AbigailGabble,AbisMal,Abu,Adella,TheAgent,AgentWendyPleakley,Akela,AltheAlligator,Aladar,Aladdin,AlamedaSlim,AlanaDale,Alana,Alcmene,Alice,AmeliaGabble,AmosSlade,Amphitryon,AnastasiaTremaine,Anda,Andrina,Angelique,AngusMacBadger';
// Split by ",":
$words = explode(',', $words);
if (count($words) == 0){ die('Wordlist is empty!'); }
// Add words while password is smaller than the given length
$pwd = '';
while (strlen($pwd) < $length){
$r = mt_rand(0, count($words)-1);
$pwd .= $words[$r];
}
$num = mt_rand(1, 99);
if ($length > 2){
$pwd = substr($pwd,0,$length-strlen($num)).$num;
} else {
$pwd = substr($pwd, 0, $length);
}
$pass_length = strlen($pwd);
$random_position = rand(0,$pass_length);
$syms = "!@#$%^&*()-+?";
$int = rand(0,51);
$rand_char = $syms[$int];
$pwd = substr_replace($pwd, $rand_char, $random_position, 0);
return $pwd;
}
?>
Password generatorPassword generator
echo random_readable_pwd(10);
?>
總結
以上是生活随笔為你收集整理的随机密码php,PHP会生成随机密码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 引用类型的转换 java,java中引用
- 下一篇: php 启动管理工具下载,phpPgAd