Php generates random password functions (four types ). The following provides four php functions for generating random passwords. The simple and practical method is a user-defined encryption function, which is difficult to crack if you do not know your encryption algorithm. The following provides the following four php functions for generating random passwords. the method is simple and practical. it is a user-defined encryption function, which is difficult to crack if you do not know your encryption algorithm.
Four models are provided belowPhp Tutorial to generate a random password functionA simple and practical method is a user-defined encryption function, which is difficult to crack if you do not know your encryption algorithm.
Method 1
Function generate_password ($ length = 8 ){
// Password character set, which can be any character you need
$ Chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789! @ # $ % ^ & * ()-_ [] {}<> ~ '+ = ,.;:/? | ';
$ Password = '';
For ($ I = 0; $ I <$ length; $ I ++)
{
// Two character acquisition methods are provided here
// Use substr to intercept any character in $ chars;
// The second method is to take any element of the character array $ chars.
// $ Password. = substr ($ chars, mt_rand (0, strlen ($ chars)-1), 1 );
$ Password. = $ chars [mt_rand (0, strlen ($ chars)-1)];
}
Return $ password;
}
Method 2
Generate 6-digit, letter, and hybrid passwords
$ Str = "0123456789 abcdefghijklmnopqrstuvwxyz"; // 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 3
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 to pass the length parameter $ pw_length = 6
Echo create_password (6 );
Method 3
Function getmicrotime ()
{
List ($ usec, $ sec) = explode ("", microtime ());
Return (float) $ usec + (float) $ sec );
}
// Record start time
$ Time_start = getmicrotime ();
// Put the php code to be executed here, for example:
// Echo create_password (6 );
// Record end time
$ Time_end = getmicrotime ();
$ Time = $ time_end-$ time_start;
// Output the total running time
Echo "execution time $ time seconds ";
?>
Bytes. Provided below...