Generates a random string, which can be used to automatically generate a password.
Features:
1. You can specify that the password contains numbers or characters. The default mode is mixed mode.
2. Specify the random password length. The default length is 6 characters.
The Code is as follows:
#-------------------------------------------
# Generate a random string, which can be used to automatically generate a password
#6-character combination of letters and numbers by default
# $ Format all number char string composition format
#-------------------------------------------
Function randStr ($ len = 6, $ format = 'all '){
Switch ($ format ){
Case 'all ':
$ Chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789 -@#~ '; Break;
Case 'Char ':
$ Chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz -@#~ '; Break;
Case 'number ':
$ Chars = '20140901'; break;
Default:
$ Chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789 -@#~ ';
Break;
}
Mt_srand (double) microtime () * 1000000 * getmypid ());
$ Password = "";
While (strlen ($ password) <$ len)
$ Password. = substr ($ chars, (mt_rand () % strlen ($ chars), 1 );
Return $ password;
}