Php user-defined random password function-PHP source code

Source: Internet
Author: User
Ec (2); & lt ;? Originally Zend.com, used by hunter reproducted *: $ new_passwordreturn_password (); example: Generate password: 2X5bjj2z, ERgid62Y, p2sHtDPv * & nbsp; copy the code functionreturn_password () as follows () {s script ec (2); script

// It turns out to be Zend.com, which is produced by hunter reproducted

/*
Usage: $ new_password = return_password ();
Example: generate password: 2X5bjj2z, ERgid62Y, p2sHtDPv
*/

The Code is as follows:

Function return_password (){

// Set password length
$ Pw_length = 8;
// Set ASCII range for random character generation
$ Low_ascii_bound = 50; // "2"
$ Upper_ascii_bound = 122; // "z"

// Exclude special characters and some confusing alphanumerics

Exclude confusion between special characters and letters and numbers
// O, O, 0, I, 1, l etc
$ Notuse = array (96,108,111 );

While ($ I <$ pw_length ){
Mt_srand (double) microtime () * 1000000 );
// Random limits within ASCII table
$ Randnum = mt_rand ($ low_ascii_bound, $ top_ascii_bound );
If (! In_array ($ randnum, $ notuse )){
$ Password = $ password. chr ($ randnum );
$ I ++;
}
}

Return $ 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.