Home > Backend Development > PHP Tutorial > PHP random password generation_PHP tutorial

PHP random password generation_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:08:50
Original
866 people have browsed it

Generate a random string that can be used to automatically generate passwords.
Features:
1. You can specify that the password contains numbers or characters, and the default is mixed mode
2. Specify any password length, the default length is 6 characters

The code is as follows:
#------------------------------------------------
# Generate a random string that can be used to automatically generate passwords
# Default length is 6 characters, mixed letters and numbers
# $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='0123456789'; 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;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629788.htmlTechArticleGenerates random strings that can be used to automatically generate passwords. Features: 1. You can specify the password to contain numbers or characters, the default is mixed mode 2. Specify any password length, the default length is 6 characters Code...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template