ランダムなパスワード生成
- PHP
-
2010-10-06 - 更新:2015-11-07
この記事は最終更新日から1年以上経過しています。
function mkCrypt()
{
// 配列生成
$ARRAY1 = range("0", "9");
$ARRAY2 = range("a", "z");
$ARRAY3 = range("A", "Z");
$ARRAY = array_merge($ARRAY1, $ARRAY2, $ARRAY3);
$a_pw = "";
$cnt = count($ARRAY) - 1;
// 乱数初期化
srand((double)microtime()*1000000);
// ランダム暗号生成
for($i = 1; $i < = 8; $i++)
{
$num = round(rand(0, $cnt));
$a_pw .= $ARRAY[$num];
}
return $a_pw;
}
または、一意なIDを生成するuniqid関数を使用する
md5(uniqid()); //php5以降のみ
md5(uniqid(rand(), true));
Apache Basic 認証用パスワード生成
function CryptBasic($id, $pw)
{
$sal = substr($id, 0, 2);
$pw_crypt = crypt($pw, $sal);
return $pw_crypt;
}
この記事がお役に立ちましたらシェアお願いします
1,398 views




