简明现代魔法 -> PHP服务器脚本 -> 调用类的静态方法生成强密码
调用类的静态方法生成强密码
2010-01-10
程序演示
geVREzGhm8程序代码
<?php
class Common {
public static function generatePassword($length = 8)
{
// start with a blank password
$password = "";
// define possible characters
$possible = "0123456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
// set up a counter
$i = 0;
// add random characters to $password until $length is reached
while ($i < $length)
{
// pick a random character from the possible ones
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
// we don't want this character if it's already in the password
if (!strstr($password, $char))
{
$password .= $char;
$i++;
}
}
// done!
return $password;
}
}
?>
<?php
$randomcode=Common::generatePassword(10);
echo $randomcode;
?>

