Home  >  Article  >  Backend Development  >  php 随机用户名与随机密码生成代码

php 随机用户名与随机密码生成代码

WBOY
WBOYOriginal
2016-08-08 09:32:291056browse
//生成随机密码functioncreate_password($pw_length= 4){    $randpwd= '';    for($i= 0; $i$pw_length; $i++){        $randpwd.= chr(mt_rand(33, 126));    }    return$randpwd;}//生成随机用户名functiongenerate_username( $length= 6 ) {    // 密码字符集,可任意添加你需要的字符    $chars= 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}~`+=,.;:/?|';    $password= '';    for( $i= 0; $i$length; $i++ )    {        // 这里提供两种字符获取方式        // 第一种是使用substr 截取$chars中的任意一位字符;        // 第二种是取字符数组$chars 的任意元素        // $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);        $password.= $chars[ mt_rand(0, strlen($chars) - 1) ];    }    return$password;} //调用$userId= 'user'.generate_username(6);$pwd= create_password(9);

以上就介绍了php 随机用户名与随机密码生成代码,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

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