Home  >  Article  >  php教程  >  生成随机密码

生成随机密码

PHP中文网
PHP中文网Original
2016-05-25 17:09:07916browse

跳至

/**
 * Order by phpno.com
 * @param num 密码的随机最小长度
 * @param num 密码的随机最大长度
 * @param bool 是否使用特殊字符
 */
function random_passwd($min_len=8,$max_len=16,$special=FALSE){
	$passwd_len = mt_rand($min_len,$max_len);
	$random_str = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";	
	$special_str = '!@#$%^&*()_+';
	if($special!=FALSE){	
		$random_str .= $special_str;
	}
	$random_passwd = '';
    while (strlen($random_passwd)<$passwd_len){
    	$random_passwd .= substr($random_str, (rand()/strlen($random_str)),1);
    }
    return $random_passwd;
}

                   

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