Here are four PHP generated random password functions Oh, simple and practical method is a user-defined encryption function, so if you do not know your encryption algorithm is difficult to crack.
Here are four php tutorials to generate random password functions Oh, simple and practical method is a user-defined encryption function, so if you do not know your encryption algorithm is difficult to crack.
Method One
function Generate_password ($length = 8) {
Password character set, you can add any character you need
$chars = ' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&* ()-_ []{}<>~ ' +=,.;:/?| ';
$password = ";
for ($i = 0; $i < $length; $i + +)
{
Here are two ways to get a character
The first is to use SUBSTR to intercept any one character in the $chars;
The second type is to take any element $chars the character array
$password. = substr ($chars, Mt_rand (0, strlen ($chars)-1), 1);
$password. = $chars [Mt_rand (0, strlen ($chars)-1)];
}
return $password;
}
Method Two
Generate 6-digit, mixed-letter passwords
$str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; Output Character Set
$n = 6; Output string length
$len = strlen ($str)-1;
for ($j =0; $j <200; $j + +) {
for ($i =0; $i < $n; $i + +) {
$s. = $str [rand (0, $len)];
}
Echo $s. "
";
$s = "";
}
?>
Automatically generate passwords for numbers, letters, and symbols
$a = "12345678";
$b = "ABCDEFGHIJKLMNOPQISTUVWXYZ";
$s = substr (str_shuffle ($a), 0, 2);
$e = substr (Str_shuffle ($b), 0, 2);
Echo $s. substr (Str_shuffle ("!@#$%^&*"), 0, 2). $e;
?>
Method Three
function Create_password ($PW _length = 8)
{
$randpwd = ";
for ($i = 0; $i < $PW _length; $i + +)
{
$randpwd. = Chr (Mt_rand (33, 126));
}
return $randpwd;
}
Call this function, pass length parameter $pw_length = 6
Echo Create_password (6);
Method Three
function Getmicrotime ()
{
List ($usec, $sec) = Explode ("", Microtime ());
return (float) $usec + (float) $sec);
}
Record start time
$time _start = Getmicrotime ();
This puts the PHP code to execute, such as:
Echo Create_password (6);
Record End time
$time _end = Getmicrotime ();
$time = $time _end-$time _start;
Total time of output run
echo "Execution time $time seconds";
?>
http://www.bkjia.com/PHPjc/632036.html www.bkjia.com true http://www.bkjia.com/PHPjc/632036.html techarticle Here are four PHP generated random password functions Oh, simple and practical method is a user-defined encryption function, so if you do not know your encryption algorithm is difficult to crack. The following is provided ...