JavaScript的随机密码生成

[url]http://www.oschina.net/code/snippet_54100_2953[/url]
function password(length, special) {
var iteration = 0;
var password = "";
var randomNumber;
if(special == undefined){
var special = false;
}
while(iteration < length){
randomNumber = (Math.floor((Math.random() * 100)) % 94) + 33;
if(!special){
if ((randomNumber >=33) && (randomNumber <=47)) { continue; }
if ((randomNumber >=58) && (randomNumber <=64)) { continue; }
if ((randomNumber >=91) && (randomNumber <=96)) { continue; }
if ((randomNumber >=123) && (randomNumber <=126)) { continue; }
}
iteration++;
password += String.fromCharCode(randomNumber);
}
return password;
}



[url]http://www.jb51.net/article/24534.htm[/url]
function randPassword() 
{
var text=['abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ','1234567890','~!@#$%^&*()_+";",./?<>'];
var rand = function(min, max){return Math.floor(Math.max(min, Math.random() * (max+1)));}
var len = rand(8, 16); // 长度为8-16
var pw = '';
for(i=0; i{
var strpos = rand(0, 3);
pw += text[strpos].charAt(rand(0, text[strpos].length));
}
return pw;
}

你可能感兴趣的:(JavaScript的随机密码生成)