白天做了个随机密码生成器,欢迎使用……
生成随机密码
默认长度8位,包括大小写字母和数字
有两个可选参数l(长度length)和t(类型type)
type的值转为二进制时低三位分别对应大写字母、小写字母、数字,和ftp里表示文件读写属性的方式类似。
还是列一下吧。
1 数字
2 小写字母
3 小写字母和数字
4 大写字母
5 大写字母和数字
6 大写字母和小写字母
7 大写字母、小写字母和数字
比如要生成长度为128位的可能包括大小写字母的密码:http://bnlt.org/rp.php?l=128&t=6
本来还意外附带了测网速的功能……不过为了我的服务器的健康着想……
源代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <?php $len = $_GET['l']; if ($len <= 0 || $len > 1024) $len = 8; $type = $_GET['t']; if ($type <= 0 || $type > 7) $type = 7; $len_of_list = 0; $list = '';
if ($type & 4) { $list .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $len_of_list += 26; } if ($type & 2) { $list .= 'abcdefghijklmnopqrstuvwxyz'; $len_of_list += 26; } if ($type & 1) { $list .= '0123456789'; $len_of_list += 10; } $rp = ''; for ($i = 0; $i < $len; $i++) { $rp .= substr($list, rand(0, $len_of_list - 1), 1); } echo $rp;
|