PHP 随机生成 用户名和 随机 密码
2011-11-19 21:06
477 查看
//自动为用户随机生成用户名(长度6-13) function create_password($pw_length = 4){ $randpwd = ''; for ($i = 0; $i < $pw_length; $i++){ $randpwd .= chr(mt_rand(33, 126)); } return $randpwd; } function generate_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生成随机用户名和密码的实现代码
- PHP生成随机用户名和密码
- PHP 随机生成 用户名和 随机 密码
- PHP生成随机用户名和密码的实现代码
- PHP生成随机用户名和密码的例子
- PHP生成随机密码的三种方法
- php生成随机密码的几种方法
- php生成随机产生六位数密码的代码
- PHP中快速生成随机密码的几种方式
- Python编程生成随机用户名及密码的方法示例
- php中生成随机密码的自定义函数代码
- php生成随机密码的几种方法
- PHP中实现随机密码生成的两种方法
- PHP生成随机密码的4种方法及性能对比
- php 随机用户名与随机密码生成代码
- php生成随机产生六位数密码的代码
- php生成随机密码的函数(转载分享)
- php 生成随机密码