Created
January 3, 2017 10:47
-
-
Save walerian777/8963e3d6a73e5afba938a3269b7ebb0d to your computer and use it in GitHub Desktop.
A function which generates a password containing at least one lowercase letter, one uppercase letter and a digit.
This file contains hidden or 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
_ = require('lodash') | |
PasswordGenerator = (length = 20) -> | |
_.map(_.shuffle(_.range(length)), (n) -> | |
switch n % 3 | |
when 0 # A digit | |
Math.floor(Math.random() * 9).toString() | |
when 1 # A lowercase letter | |
String.fromCharCode(Math.floor(Math.random() * 26) + 97) | |
when 2 # An uppercase letter | |
String.fromCharCode(Math.floor(Math.random() * 26) + 65) | |
).join('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment