Method One
The code is as follows |
Copy Code |
function Generate_password ($length = 8) { //password character set, you can add any character you need $chars = ' Abcdefghij klmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&* ()-_ []{}<>~ ' +=,.;:/?| '; $password = '; for ($i = 0; $i < $length; $i + +) { //Here are two character capture methods //The first is to use SUBSTR to intercept any one character in the $chars; //The second is any element that takes a character array $chars $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, letter mixed password
The code is as follows |
Copy Code |
<?php $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. "<br/>"; $s = ""; } ?> Automatically generate passwords for numbers, letters, and symbols <?php $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
The code is as follows |
Copy Code |
function Create_password ($PW _length = 8) { $randpwd = '; for ($i = 0; $i < $PW _length; $i + +) { $randpwd. = Chr (Mt_rand (33, 126)); } return $randpwd; } Call the function, passing the length parameter $pw_length = 6 Echo Create_password (6); |
Method Three
code is as follows |
copy code |
<?php Function Getmicrotime () { list ($usec, $sec) = Explode ("", Microtime ()); return ((float) $usec + (float) $sec); } //Record start time $time _start = Getmicrotime (); //Here is the PHP code to execute, such as: //EC Ho Create_password (6); //Record end time $time _end = Getmicrotime (); $time = $time _end-$time _start; //output Run total time echo "Execution time $time seconds"; ? |