如何修改其中一个示例,在密码中至少包含一个大写和一个nubmer?
http://javascript.internet.com/passwords/password-generator.html
http://www.blazonry.com/javascript/password.php
或任何其他示例:)
答案 0 :(得分:13)
脱离我的头顶:
function generatePassword(len){
var pwd = [], cc = String.fromCharCode, R = Math.random, rnd, i;
pwd.push(cc(48+(0|R()*10))); // push a number
pwd.push(cc(65+(0|R()*26))); // push an upper case letter
for(i=2; i<len; i++){
rnd = 0|R()*62; // generate upper OR lower OR number
pwd.push(cc(48+rnd+(rnd>9?7:0)+(rnd>35?6:0)));
}
// shuffle letters in password
return pwd.sort(function(){ return R() - .5; }).join('');
}