PHP two methods to generate a strong password

Source: Internet
Author: User

Effect demonstration

First generation method: o6rkNmI0f

Second Generation Method: 745 IFsXt?

PHP code

Method 1

<? Php $ password_length = 9; function make_seed () {list ($ usec, $ sec) = explode ('', microtime (); return (float) $ sec + (float) $ usec * 100000);} srand (make_seed (); // random character set $ alfa = "1234567890 bytes"; $ token = ""; for ($ I = 0; $ I <$ password_length; $ I ++) {$ token. = $ alfa [rand (0, strlen ($ alfa)];} echo $ token;?>

Second Generation Method

<? Php // create password $ totalChar = 8; // Number of strings in the password // salt to select chars from $ salt = "regular"; srand (double) microtime () * 1000000); // start the random generator $ Spass = ""; // set the initial value for ($ I = 0; $ I <$ totalChar; $ I ++) // create a password cyclically $ Spass = $ Spass. substr ($ salt, rand () % strlen ($ salt), 1); echo $ Spass;?>?

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.