Php generates a secure and random password program. Php generates a random password, which is convenient and fast, and can generate a secure and reliable password randomly. I hope this article will help you. The sample code is as follows: Copy the code? Phpheader (Content-php generates a random password, which is convenient and quick. you can generate a secure and reliable password at random. I hope this article will help you.
Example
The code is as follows: |
|
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 ?>
|
Password Generation
Example 2: The first image
1. preset a string $ chars, including A-z, a-Z, 0-9, and some special characters
2. random character in $ chars string
3. Repeat step 2 n times to obtain a password with a length of n.
The code is as follows: |
|
Function generate_password ($ length = 8 ){ // Password character set, which can be any character you need $ Chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789! @ # $ % ^ & * ()-_ [] {}<> ~ '+ = ,.;:/? | '; $ Password = ''; For ($ I = 0; $ I <$ length; $ I ++) { // Two character acquisition methods are provided here // Use substr to intercept any character in $ chars; // The second method 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; } |
Bytes. The sample code is as follows? Php header (Content -...