Created
April 24, 2012 18:43
-
-
Save shawnlauzon/2482527 to your computer and use it in GitHub Desktop.
Generate a password of the given size using any set of characters
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
int password_length = 12 | |
if (args.size() > 0) { | |
password_length = args[0] as int | |
} | |
String validChars ="qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM" | |
int maxIndex = validChars.length() | |
def rnd = new Random() | |
def password = (1..password_length).sum { | |
validChars[rnd.nextInt(maxIndex)] | |
} | |
println(password) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment