-
-
Save unicornist/70579ed24d0334bce2e0ac2b1ecf0a3d to your computer and use it in GitHub Desktop.
Generate secure and readable password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// just translated from the php version (I have to optimise it) | |
function generatePassword (length) { | |
if(!length) length = 8; | |
var sets = ['abcdefghjkmnpqrstuvwxyz', 'ABCDEFGHJKMNPQRSTUVWXYZ', '23456789', '~!@#$^*()_.-=+']; | |
var all = ''; | |
var password = ''; | |
sets.forEach(function(set){ | |
set = shuffle(set); | |
password += set[0]; | |
all += set; | |
}); | |
for(var i=0; i<length-sets.length; i++) { | |
all = shuffle(all); | |
password += all[0]; | |
} | |
password = shuffle(password); | |
return password; //'Uc74T?y$' | |
} | |
function shuffle (str) { | |
var a = str.split(""), n = a.length; | |
for(var i = n - 1; i > 0; i--) { | |
var j = Math.floor(Math.random() * (i + 1)); | |
var tmp = a[i]; | |
a[i] = a[j]; | |
a[j] = tmp; | |
} | |
return a.join(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just translated from the php version (I have to optimise it)