Skip to content

Instantly share code, notes, and snippets.

@walerian777
Created January 3, 2017 10:47
Show Gist options
  • Save walerian777/8963e3d6a73e5afba938a3269b7ebb0d to your computer and use it in GitHub Desktop.
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.
_ = 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