Skip to content

Instantly share code, notes, and snippets.

@tuki0918
Created May 11, 2013 11:54
Show Gist options
  • Save tuki0918/5559769 to your computer and use it in GitHub Desktop.
Save tuki0918/5559769 to your computer and use it in GitHub Desktop.
Password =
SYMBOL: '!"#$%&\'()'
NUMBER: '1234567890'
ABC_L: 'abcdefghijklmnopqrstuvwxyz'
ABC_U: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
generate: (len)->
password = ''
# 11以下 -> 12, 17以上 -> 16
len = 12 if typeof len is 'undefined' or len <= 11
len = 16 if len >= 17
key = (Password.NUMBER + Password.SYMBOL + Password.ABC_L + Password.ABC_U).split('')
keyLen = key.length
for i in [1..len]
password += key[Math.floor(Math.random() * keyLen)]
return password
# パスワードの作成
for i in [10..18]
console.log "#{i}: #{Password.generate(i).length}" #{Password.generate(i)}"
# console.log Password.generate(14)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment