Skip to content

Instantly share code, notes, and snippets.

@m0er
Created August 1, 2012 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m0er/3222883 to your computer and use it in GitHub Desktop.
Save m0er/3222883 to your computer and use it in GitHub Desktop.
jQuery password generator
// http://jquery-howto.blogspot.kr/2009/10/javascript-jquery-password-generator.html
$.extend({
password: function (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;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment