Home  >  Article  >  Backend Development  >  Custom function to generate random password in php_PHP tutorial

Custom function to generate random password in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:17:23758browse

A function that generates a random password. The generated password is a random string of lowercase letters and numbers, with a customizable length.

/*
 * php自动生成新密码自定义函数(带实例演示)
      适用环境: PHP5.2.x  / mysql 5.0.x
       代码作者: xujiajay www.jbxue.com
       联系方式: xujiaphp@gmail.com
* */
function genPassword($min = 5, $max = 8)  
{  
    $validchars="abcdefghijklmnopqrstuvwxyz123456789";  
    $max_char=strlen($validchars)-1;  
    $length=mt_rand($min,$max);  
    $password = "";  
    for($i=0;$i<$length;$i )  
    {  
        $password.=$validchars[mt_rand(0,$max_char)];  
    }  
        return $password;  
    }  
    echo "新密码:".genPassword()."<br-->";  
    echo "新密码:".genPassword(5,10)."
";
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/625811.htmlTechArticleA function that generates a random password. The generated password is a random string of lowercase letters and numbers. The length can be customized. . /* * PHP automatically generates a new password custom function (with example demonstration)...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn