随机密码生成器

白天做了个随机密码生成器,欢迎使用……

生成随机密码

默认长度8位,包括大小写字母和数字

有两个可选参数l(长度length)和t(类型type)

type的值转为二进制时低三位分别对应大写字母、小写字母、数字,和ftp里表示文件读写属性的方式类似。

还是列一下吧。

1 数字

2 小写字母

3 小写字母和数字

4 大写字母

5 大写字母和数字

6 大写字母和小写字母

7 大写字母、小写字母和数字

比如要生成长度为128位的可能包括大小写字母的密码:http://bnlt.org/rp.php?l=128&t=6

本来还意外附带了测网速的功能……不过为了我的服务器的健康着想……

源代码如下:

<?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;
This entry was posted in 程序设计 and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">