Two methods for generating strong passwords in PHP

Source: Internet
Author: User

Here are 2 kind PHP code can generat strong passwords:

$ Password_length = 9;

Function make_seed (){
List ($ USEC, $ Sec) = explode ('', microtime ());
Return (float) $ sec + (float) $ USEC * 100000 );
}

Srand (make_seed ());

$ Alfa = "1234567890qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm ";
$ Token = "";
For ($ I = 0; $ I <$ password_length; $ I ++ ){
$ Token. = $ Alfa [rand (0, strlen ($ Alfa)];
}
Echo $ token;

--

// Create Password
$ Totalchar = 8; // Number of chars in the password
$ Salt = "abcdefghijklmnpqrstuvwxyzabcdefghijklmnpqrstuvwxyz123456789"; // salt to select chars from
Srand (double) microtime () * 1000000); // start the random Generator
$ Spass = "; // set the in‑variable
For ($ I = 0; $ I <$ totalchar; $ I ++) // loop and create Password
$ Spass = $ spass. substr ($ salt, Rand () % strlen ($ salt), 1 );

Run this in a loop to generate as your password as you want.

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.