码迷,mamicode.com
首页 > 其他好文 > 详细

生成随机密码

时间:2017-05-29 21:09:22      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:code   eric   seed   rand   cep   srand   log   and   for   

<?php
 function make_password($num_chars) {
    if ((is_numeric($num_chars)) &&
        ($num_chars > 0) &&
        (! is_null($num_chars))) {
        $password = ‘‘;
        $accepted_chars = ‘abcdefghijklmnopqrstuvwxyz1234567890‘;
        // Seed the generator if necessary.
        srand(((int)((double)microtime()*1000003)) );
        for ($i=0; $i<=$num_chars; $i++) {
            $random_number = rand(0, (strlen($accepted_chars) -1));
            $password .= $accepted_chars[$random_number] ;
        }
        return $password;
     }
}

 

生成随机密码

标签:code   eric   seed   rand   cep   srand   log   and   for   

原文地址:http://www.cnblogs.com/719907411hl/p/6918980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!