Home  >  Article  >  Backend Development  >  PHP random password generator_PHP tutorial

PHP random password generator_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:55:00729browse

I found a PHP random password generation program from a foreign website. You can first define the base, and then use mt_rand and substr to get the Nth character.

Randomly generated password: m1ztpxw8

 代码如下 复制代码
function genPwd($length=6) {
$password = '';
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$i = 0;
while ($i < $length) {

$password .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}

return $password;
}
?>

Test method

The code is as follows
 代码如下 复制代码

$password = genPwd(8);
?>

Copy code
$password = genPwd(8);
?>

http://www.bkjia.com/PHPjc/631699.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/631699.html
TechArticle
A PHP random password generation program found from foreign websites. You can first define the base, and then use mt_rand and substr comes in to get the Nth character. Randomly generated password: m1ztp...
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