PHP generates a random password, easy and fast, can randomly generate a secure and reliable password, I hope this article will be helpful to everyone.
Cases
The code is as follows |
Copy Code |
Header ("Content-type:text/html;charset=utf-8"); function Getrandpass ($length = 6) { $password = "; Add the characters you want to the following string, which is the number 0-9 and the 26 English letters by default $chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $char _len = strlen ($chars); for ($i =0; $i < $length; $i + +) { $loop = Mt_rand (0, ($char _len-1)); Take this string as an array, randomly take out a character, and loop it into the number of bits you need. $password. = $chars [$loop]; } return $password; } Echo Getrandpass (12); Randomly generate a 12-digit password ?>
|
Generate password which next
Example 2, with the first one a little like
1. Preset a string $chars, including a–z,a–z,0–9, and some special characters
2. Randomly take a character in a $chars string
3, repeat the second step n times, can get the length of the password of n
|
copy code |
function Generate_password ($length = 8) { Password character set, you can add any character you need $chars = ' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&* ()-_ [ ]{}<>~ ' +=,.;:/?| '; $password = '; for ($i = 0; $i < $length; $i + +) { //provides two ways to get a character here //The first is to use SUBSTR to intercept any one character in the $chars; //The second is the word-taking Any element //$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.html www.bkjia.com true http://www.bkjia.com/PHPjc/632821.html techarticle PHP generates a random password, easy and fast, can randomly generate a secure and reliable password, I hope this article will be helpful to everyone. Example code copy Code as follows? PHP header (Content-...