Last active
December 14, 2015 05:48
-
-
Save ahultgren/5037567 to your computer and use it in GitHub Desktop.
Basic password generator. Larger feed base than most other generators (and thus higher entropy) and let's you choose which character composition to use. Quotes are for example confusing to put in a session secret on the server, so exclude chars.ambigious. The PRNG can definitely be improved, as could the character collection. Right now, all char…
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
var chars = { | |
numbers: "123456789", | |
letters: "qwertyupasdfghjkzxcvbnm", | |
upper: "qwertyupasdfghjkzxcvbnm".toUpperCase(), | |
special: "!#€%&/@\\(){}[]=?`´^¨*,.;:-_><§°", | |
foreign: "ñõìàéèëêãâîïÇÉçéûüåäöæø", | |
foreignUpper: "ñõìàéèëêãâîïÇÉçéûüåäöæø".toUpperCase(), | |
ambigious: "”\"'’“iloILO0 ", | |
insane: "¡¥¢‰¶≠¿•˝√‡˜ˆŒ∏»«ˇ⁄—·◊∑∆∫¯˘¬ºflØÆ⁄ˇ≥Ω鮆µüıœπ˙ß∂ƒ¸˛ªfi÷≈ç‹›‘‚…" | |
}; | |
function generatePassword (length, collection) { | |
var result = "", i; | |
collection = collection.map(function (item) { | |
return chars[item]; | |
}).join(''); | |
for(i = length; i--;) { | |
result += collection[Math.floor(Math.random()*collection.length)]; | |
} | |
return result; | |
} | |
// Usage example | |
console.log(generatePassword(30, ['numbers', 'letters', 'upper', 'special', 'foreign', 'foreignUpper', 'insane'])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rebuilt into a module here! https://github.com/ahultgren/node-password-generator