JavaScript的随机密码生成
http://www.oschina.net/code/snippet_54100_2953
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Js代码 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; } |
http://www.jb51.net/article/24534.htm
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Js代码 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<len; ++i) { var strpos = rand(0, 3); pw += text[strpos].charAt(rand(0, text[strpos].length)); } return pw; } |
