PHP生成随机密码,并计算所用时间
来源:互联网 发布:北京青少年行知实践园 编辑:程序博客网 时间:2024/05/22 06:47
<?phpfunction create_password($pw_length = 8){$randpwd = '';for ($i = 0; $i < $pw_length; $i++){$randpwd .= chr(mt_rand(33, 126));}return $randpwd;}// 调用该函数,传递长度参数$pw_length = 6echo create_password(16);echo '<hr/>';function generate_password( $length = 8 ){// 密码字符集,可任意添加你需要的字符$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;}echo generate_password();echo '<hr/>';function make_password( $length = 8 ){// 密码字符集,可任意添加你需要的字符$chars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l','m', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y','z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L','M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y','Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '@','#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '[', ']', '{', '}', '<', '>', '~', '`', '+', '=', ',', '.', ';', ':', '/', '?', '|');// 在 $chars 中随机取 $length 个数组元素键名$keys = array_rand($chars, $length);$password = '';for($i = 0; $i < $length; $i++){// 将 $length 个数组元素连接成字符串$password .= $chars[$keys[$i]];}return $password;}echo make_password(6);echo '<hr/>';//记录时间function getmicrotime(){list($usec, $sec) = explode(" ",microtime());return ((float)$usec + (float)$sec);}// 记录开始时间$time_start = getmicrotime();// 这里放要执行的PHP代码,如:// echo create_password(6);// 记录结束时间$time_end = getmicrotime();$time = $time_end - $time_start;// 输出运行总时间echo "执行时间 $time seconds";?>
更多精彩博文请到言会咸的博客
网址:http://blog.csdn.net/aoyoo111
0 0
- PHP生成随机密码,并计算所用时间
- 生成随机密码_并计算用时
- 例6 用LabVIEW计算生成等于某个给定值的随机数据所用时间
- 【例6】计算生成等于某个给定值的随机数据所用时间
- php生成随机密码
- PHP 生成随机密码
- PHP生成随机密码
- php 生成随机密码
- PHP随机密码的生成
- PHP 自动生成随机密码
- PHP 随机生成 用户名和 随机 密码
- php生成随机密码的练习记录
- php生成随机密码的方法总结
- PHP生成随机用户名和密码
- PHP生成随机密码的方法
- 【PHP】浅谈生成随机密码的方法
- php之上传小案例,根据时间:月日分创建目录并随机生成文件名
- 计算代码段所用时间
- javaFile循环列出指定目录下的所有文件(源代码)
- SAX解析XML文件实例代码
- Dom解析xml源代码
- java UDP网路编程
- 多家在线考试系统对比分析
- PHP生成随机密码,并计算所用时间
- 费用流 模板 MCMF
- php获取随机数 js获取随机数 js四舍五入,保留小数位数
- Ruby: Sorting an array of strings, in alphabetical order, that includes some arrays of strings
- PHP使用Apache中的ab测试网站的压力性能
- Boost.Asio的使用技巧
- Lua学习之字符串函数及模式匹配
- 应用curl扩展抓取网页
- VisualC++ WindowsForm不规则窗体的绘制