Skip to content

Instantly share code, notes, and snippets.

@olih
Created August 14, 2013 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olih/6230090 to your computer and use it in GitHub Desktop.
Save olih/6230090 to your computer and use it in GitHub Desktop.
Generate a random password for admin purposes
#
#Creator: 2013, Olivier Huin (https://github.com/olih)
#License: Eclipse Public License - v 1.0
#Contributors:
#
# Generates a random password
#This code is a quick hack and should not be used for production
#as it is not optimized and the random numbers could be predicted.
G=10000000000
PUNCT=['{','}','[',']','!','@','£','$','%',
'^','*','(',')',':',';',"'",'"',
'|','~',',','.','/','?']
generateLowerChars = ()->
num=Math.floor(Math.random()*9*G) + G;
return num.toString(36)
generateLowerString= (size)->
div=Math.ceil(size/7)
r = ""
for i in [0..div]
r=r+generateLowerChars()
r=r.substring(0,size)
return r;
generateString= (size)->
t=generateLowerString(size)
r=""
for c in t
if Math.random()>0.5
r=r+c.toUpperCase()
else
r=r+c
return r
generatePass= (size)->
t=generateString(size)
r=""
for c in t
num=Math.floor(Math.random()*PUNCT.length);
if Math.random()<0.25
r=r+PUNCT[num]
else
r=r+c
return r
#Generate a 15 chars password
console.log generatePass(15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment