Heim  >  Artikel  >  php教程  >  php生成随机密码的自定义函数(转载分享),php自定义

php生成随机密码的自定义函数(转载分享),php自定义

WBOY
WBOYOriginal
2016-06-13 09:10:151066Durchsuche

php生成随机密码的自定义函数(转载分享),php自定义

php生成随机密码的自定义函数

发布时间:2015-03-24编辑:脚本学堂
php生成随机密码的自定义函数  

生成一个随机密码的函数,生成的密码为小写字母与数字的随机字符串,长度可自定义。
 

复制代码代码如下: /*
 * php自动生成新密码自定义函数(带实例演示)
      适用环境: PHP5.2.x  / mysql 5.0.x
       代码作者: xujiajay
       联系方式: 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    {  
        $password.=$validchars[mt_rand(0,$max_char)];  
    }  
        return $password;  
    }  
    echo "新密码:".genPassword()."
";  
    echo "新密码:".genPassword(5,10)."
";
?>

 本文转自脚本学堂 http://www.jbxue.com
查看原文:php生成随机密码的自定义函数

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn