Home >Backend Development >PHP Tutorial >Pure php generates random passwords, php generates_PHP tutorial

Pure php generates random passwords, php generates_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:06:03883browse

Pure php generates a random password, php generates

php generates a random password, which is convenient and fast, and can randomly generate safe and reliable passwords.

Share the code as follows

<&#63;php

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<$length;$i++){
 $loop = mt_rand(0, ($char_len-1));
 //将这个字符串当作一个数组,随机取出一个字符,并循环拼接成你需要的位数
 $password .= $chars[$loop];
 }
 return $password;
}
echo getRandPass(12); //随机生成一个12位数的密码

&#63;>
 

I hope this article will be helpful to everyone in learning PHP programming. You can try to change the number of digits in the generated password. I hope you like it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1066503.htmlTechArticlePure php generates a random password, php generates php to generate a random password, which is convenient and fast, and can randomly generate safe and reliable passwords. password. The shared code is as follows phpheader("Content-type:text/html...
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