Home > php教程 > PHP源码 > body text

生成随机密码

PHP中文网
Release: 2016-05-25 17:09:07
Original
853 people have browsed it

跳至

/**
 * 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;
}
Copy after login

                   

Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!