PHP generates random password (php custom function)

高洛峰
Release: 2016-10-10 10:16:32
Original
939 people have browsed it

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 code 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($val idchars)-1;
$length=mt_rand($min,$max);
$password = "";
for($i=0;$i {
$password.=$validchars[mt_rand(0, $max_char)];
}
} return $password;
}
echo "New password: ".genPassword()."
";
echo "New password: ".genPassword(5,10)."
";
?>

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template