Home > Article > Backend Development > PHP generates a secure and random password program_PHP tutorial
php generates a random password, which is convenient and fast. It can randomly generate safe and reliable passwords. I hope this article will be helpful to everyone.
Example
The code is as follows
|
Copy code
|
||||
header("Content-type:text/html;charset=utf-8"); function getRandPass($length = 6){
| $chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for($i=0;$i $loop = mt_rand(0, ($char_len-1)); //Treat this string as an array, randomly pick out a character, and loop to splice it into the number of digits you need $password .= $chars[$loop]; } return $password; } echo getRandPass(12); //Randomly generate a 12-digit password
The code is as follows | Copy code |
function generate_password( $length = 8 ) { // Password character set, you can add any characters you need $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}~`+=,.;:/?|'; $password = ''; for ( $i = 0; $i { //There are two ways to obtain characters // The first is to use substr to intercept any character in $chars; is to take any element of the character array $chars // $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); $password .= $chars[ mt_rand(0, strlen($chars) - 1) ]; } return $password; } http://www.bkjia.com/PHPjc/632821.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632821.htmlTechArticlephp generates a random password, which is convenient and fast. It can randomly generate safe and reliable passwords. I hope this article will be useful to everyone. Helps. Example code is as follows Copy code ?php header(Content-... |