Skip to content

Instantly share code, notes, and snippets.

@AlexMcowkin
Created June 23, 2015 14:58
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 AlexMcowkin/f0e24df09c42ec087f47 to your computer and use it in GitHub Desktop.
Save AlexMcowkin/f0e24df09c42ec087f47 to your computer and use it in GitHub Desktop.
JS: random password generator
<input id="usersmodel-pwd" name="UsersModel[pwd]" value="" type="text">
<a href="#generatepassword" id="generatepassword"><span>сгенерировать пароль</span></a>
$('#generatepassword').click(function(e){
e.preventDefault();
var i, x, chars, pass;
var usersModelPwd = function(){
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!#$@";
pass = "";
for(x=0;x<8;x++)
{
i = Math.floor(Math.random() * 62);
pass += chars.charAt(i);
}
return pass;
}
$('#usersmodel-pwd').val(usersModelPwd);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment