Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript password generator

Tags:

javascript

What would be the best approach to creating a 8 character random password containing a-z, A-Z and 0-9?

Absolutely no security issues, this is merely for prototyping, I just want data that looks realistic.

I was thinking a for (0 to 7) Math.random to produce ASCII codes and convert them to characters. Do you have any other suggestions?

like image 496
peirix Avatar asked Sep 30 '09 11:09

peirix


People also ask

Can password generators be hacked?

Can't app makers be hacked, too? The quick answer is “yes.” Password managers can be hacked. But while cybercriminals may get "in" it doesn't mean they will get your master password or other information. The information in your password manager is encrypted.


1 Answers

I would probably use something like this:

function generatePassword() {     var length = 8,         charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",         retVal = "";     for (var i = 0, n = charset.length; i < length; ++i) {         retVal += charset.charAt(Math.floor(Math.random() * n));     }     return retVal; } 

That can then be extended to have the length and charset passed by a parameter.

like image 58
Gumbo Avatar answered Sep 21 '22 06:09

Gumbo