php custom function to generate random password (reprint and share), php customization
php custom function to generate random password
- Release time: 2015-03-24 Editor: Script School
Custom function to generate random password in php
A function that generates a random password. The generated password is a random string of lowercase letters and numbers, and the length can be customized.
Copy codeThe code is as follows:
/*
* php automatically generates a new password custom function (with example demonstration)
Applicable environment: PHP5.2.x / mysql 5.0.x
Code author: xujiajay
Contact: 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; .genPassword()."
";
echo "New password:".genPassword(5,10)."
";
?>
This article is reproduced from Scripting School http://www.jbxue.com
View original text: Custom function for generating random passwords in PHP
http://www.bkjia.com/PHPjc/972512.html
www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/972512.htmlTechArticlephp custom function to generate random passwords (reprint and share), php custom php custom function to generate random passwords Release time: 2015-03-24 Editor: Script School php automatically generates random passwords...