Created
August 14, 2013 11:09
-
-
Save olih/6230090 to your computer and use it in GitHub Desktop.
Generate a random password for admin purposes
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
# | |
#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