Home  >  Article  >  Backend Development  >  PHP generates random password custom function code (simple and fast)_PHP tutorial

PHP generates random password custom function code (simple and fast)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:30:01826browse

Implement the code, copy and use:

header("Content-type:text/html;charset=utf-8");
function getRandPass($length = 6){
$password = '';
//Add the characters you want to the string below, the default is numbers 0-9 and 26 English letters
$chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
$char_len = strlen($chars);
for($i=0;$i<$length;$i++){
$loop = mt_rand(0, ($char_len-1) );
//Treat this string as an array, randomly pick out a character, and loop into the number of digits you need
$password .= $chars[$loop];
}
return $password;
}
echo getRandPass(12); //Randomly generate a 12-digit password

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/768134.htmlTechArticleImplement the code, copy and use: ?php header("Content-type:text/html;charset=utf- 8"); function getRandPass($length = 6){ $password = ''; //Add the characters you want to the string below...
Statement:
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