Maison  >  Article  >  développement back-end  >  php生成随机密码自定义函数代码(简单快速)_PHP教程

php生成随机密码自定义函数代码(简单快速)_PHP教程

WBOY
WBOYoriginal
2016-07-13 10:30:01826parcourir

实现代码,复制即用:

header("Content-type:text/html;charset=utf-8");
function getRandPass($length = 6){
 $password = '';
 //将你想要的字符添加到下面字符串中,默认是数字0-9和26个英文字母
 $chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
 $char_len = strlen($chars);
 for($i=0;$i  $loop = mt_rand(0, ($char_len-1));
  //将这个字符串当作一个数组,随机取出一个字符,并循环拼接成你需要的位数
  $password .= $chars[$loop];
 }
 return $password;
}
echo getRandPass(12); //随机生成一个12位数的密码

?>

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/768134.htmlTechArticle实现代码,复制即用: ?php header("Content-type:text/html;charset=utf-8"); function getRandPass($length = 6){ $password = ''; //将你想要的字符添加到下面字符串...
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn