PHP generates random cipher functions (four models) _php tutorial

Source: Internet
Author: User
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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.