Home  >  Article  >  php教程  >  PHP generates random password (php custom function) transferred from Pioneer Tutorial Network

PHP generates random password (php custom function) transferred from Pioneer Tutorial Network

WBOY
WBOYOriginal
2016-09-15 11:14:401012browse

php generates random password (php custom function)

Time: 2015-12-16 20:43:49 Source: Internet
Introduction: PHP random password generation code, use PHP custom function to generate a random password of specified length. The password rules are a random string of lowercase letters and numbers, and the length can be customized.

A function that generates a random password. The password is a random string of lowercase letters and numbers. The length can be customized.

Copy the codeThe code is as follows:
/*
* php automatically generates new password custom function (with example demonstration)
Applicable environment: PHP5.2.x / mysql 5.0.x
Code author: xujiajay
Contact information: 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<$length;$i++ )
{
$password.=$validchars[mt_rand(0,$max_char)];
}
return $password;
}
echo "New password:".genPassword()."
";
echo "New password:".genPassword(5,10)."
";
?> ;
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