生成随机密码函数

两个产生随机密码函数:
函数一:

function randomPassword($passwordLength = 8)
{
    
$str = "abcefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    
if($passwordLength > strlen($str))
        
$passwordLength = strlen($str);
    
if($passwordLength < 8)
        
$passwordLength = 8;
    
$start = mt_rand(1, (strlen($str- $passwordLength));
    
$string = str_shuffle($str);
    
$password = substr($string, $start, $passwordLength);
    
return($password);
}

函数二:
function randomPassword($passwordLength=8)
{
    
//密码字符串
    define("PASS_STRING","ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");    
       
    
if($passwordLength < 8)
        
$passwordLength = 8;
    
for($i = 1$i <= $passwordLength$i++)
    {
        
$randomPosition = rand(0, strlen(PASS_STRING)-1);
        
$password .= substr(PASS_STRING, $randomPosition, 1);
    }
    
return $password;
}
原文地址:https://www.cnblogs.com/ywkpl/p/1054077.html