0
私は完璧に動作するこのランダムパスワードスクリプトを書いています。PHPはランダムなパスワードスクリプトで発音を確認します
ランダムパスワードには、phaneticアルファベットを示す以下の行を追加したいと思いますが、
これを実装するにはどうすればよいでしょうか?
<?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';
$phonetic = array("a"=>"alfa","b"=>"bravo","c"=>"charlie","d"=>"delta","e"=>"echo","f"=>"foxtrot","g"=>"golf","h"=>"hotel","i"=>"india","j"=>"juliett","k"=>"kilo","l"=>"lima","m"=>"mike","n"=>"november","o"=>"oscar","p"=>"papa","q"=>"quebec","r"=>"romeo","s"=>"sierra","t"=>"tango","u"=>"uniform","v"=>"victor","w"=>"whisky","x"=>"x-ray","y"=>"yankee","z"=>"zulu");
// 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 = "[email protected]#%^*()-?";
$int = rand(0,9);
$rand_char = $syms[$int];
$pwd = substr_replace($pwd, $rand_char, $random_position, 0);
return $pwd;
}
?>
<html><head><title>Password generator</title></head>
<body><p><?php echo random_readable_pwd(10); ?></p></body>
</html>
例えば出力:!
AltキーheAll87
ALFAのリマのタンゴ!ホテルエコーアルファリマリマ8 7
ありがとう、私は文字列の長さを使用して各文字をループする必要があることを理解します。私が理解できない難しい部分は、表音的な配列に置き換えて、ケースをテストすることです。 –
@JohnMagnolia上記の編集を参照してください! :) –
初めはすごくうまくいったよ、ありがとう。それぞれの文字を特定するためにsubstrに$ iを使用した方法がわかります。 –