<script type="text/javascript">
var PasswordCharArray = ['ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz', '1234567890', '~!@#$%^&*()_+;,./?<>'];
function RandomPassword(length, type){
var rand = function(min, max){return Math.floor(Math.max(min, Math.random() * (max+1)));}
var pw = '';
var tmpArray = new Array();
if(type.indexOf('A') != -1){
tmpArray.push(PasswordCharArray[0]);
}
if(type.indexOf('a') != -1){
tmpArray.push(PasswordCharArray[1]);
}
if(type.indexOf('1') != -1){
tmpArray.push(PasswordCharArray[2]);
}
if(type.indexOf('S') != -1){
tmpArray.push(PasswordCharArray[3]);
}
for(i=0; i<length; i++){
var strpos = rand(0, tmpArray.length-1);
pw += tmpArray[strpos].charAt(rand(0, tmpArray[strpos].length-1));
}
return pw;
}
document.write(RandomPassword(16, 'Aa1')); //输出大写字母、小写字母、数字随机组成的16位长度的密码
document.write(RandomPassword(16, 'Aa1S')); //输出大写字母、小写字母、数字、字符随机组成的16位长度的密码
</script>
基于本函数扩展出的在线密码生成器请看这个链接:http://codeclip.com/tools/zaixianmimashengcheng.html
右键查看源代码保存为html文件,放在你网站的任意位置就可以使用啦。