Php generate random password User-Defined Function Code (simple and fast) _ php instance

Source: Internet
Author: User
It is a headache to think about passwords one by one when creating a large number of users. Using php to randomly generate a secure and reliable password is convenient and fast, and you can add your own strings, you can use the FTP password, Mysql password, and website background password to implement code:

Header ("Content-type: text/html; charset = UTF-8 ");
Function getRandPass ($ length = 6 ){
$ Password = '';
// Add the desired character to the following string. The default value is 0-9 and 26 English letters.
$ Chars = "0123456789 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
$ Char_len = strlen ($ chars );
For ($ I = 0; $ I <$ length; $ I ++ ){
$ Loop = mt_rand (0, ($ char_len-1 ));
// Use this string as an array, randomly retrieve a character, and concatenate it into the desired number of digits.
$ Password. = $ chars [$ loop];
}
Return $ password;
}
Echo getRandPass (12); // generate a random 12-digit password

?>

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.