下面提供了四款php產生隨機密碼函數哦,方法簡單實用是一款使用者自定的加密函數,這樣如果不知道你的密碼編譯演算法是很難破解的。
下面提供了四款php教程產生隨機密碼函數哦,方法簡單實用是一款使用者自定的加密函數,這樣如果不知道你的密碼編譯演算法是很難破解的。
方法一
function generate_password( $length = 8 ) {
// 密碼字元集,可任意添加你需要的字元
$chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
$password = '';
for ( $i = 0; $i < $length; $i++ )
{
// 這裡提供兩種字元擷取方式
// 第一種是使用 substr 截取$chars中的任意一位字元;
// 第二種是取字元數組 $chars 的任意元素
// $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
$password .= $chars[ mt_rand(0, strlen($chars) - 1) ];
}
return $password;
}
方法二
動產生6位元字、字母 混合密碼
$str = "0123456789abcdefghijklmnopqrstuvwxyz"; // 輸出字元集
$n = 6; // 輸出串長度
$len = strlen($str)-1;
for($j=0 ; $j<200 ; $j++){
for($i=0 ; $i<$n; $i++){
$s .= $str[rand(0,$len)];
}
echo $s . "
";
$s = "";
}
?>
自動產生數字、字母、符號的密碼
$a = "12345678";
$b = "abcdefghijklmnopqistuvwxyz";
$s = substr(str_shuffle($a), 0, 2);
$e = substr(str_shuffle($b), 0, 2);
echo $s . substr(str_shuffle("!@#$%^&*"), 0, 2) . $e;
?>
方法三
function create_password($pw_length = 8)
{
$randpwd = '';
for ($i = 0; $i < $pw_length; $i++)
{
$randpwd .= chr(mt_rand(33, 126));
}
return $randpwd;
}
// 調用該函數,傳遞長度參數$pw_length = 6
echo create_password(6);
方法三
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
// 記錄開始時間
$time_start = getmicrotime();
// 這裡放要執行的php代碼,如:
// echo create_password(6);
// 記錄結束時間
$time_end = getmicrotime();
$time = $time_end - $time_start;
// 輸出運行總時間
echo "執行時間 $time seconds";
?>
http://www.bkjia.com/PHPjc/632036.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632036.htmlTechArticle下面提供了四款php產生隨機密碼函數哦,方法簡單實用是一款使用者自定的加密函數,這樣如果不知道你的密碼編譯演算法是很難破解的。 下面提供...