Last active
September 9, 2015 17:00
-
-
Save prmichaelsen/5daec5d81df5b89a15e9 to your computer and use it in GitHub Desktop.
Takes command line arguments length and number and generates passwords (alphanumeric and special 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
//******************************************************************* | |
// Java compiler created in PHP to quickly and safely test code. | |
// NOTE: please read the 'More Info' tab to the right for shortcuts. | |
//******************************************************************* | |
import java.lang.Math; // header stuff MUST go above the first class | |
import java.util.Random; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
// our main class becomes a file but the main method is still found | |
//TAKES ARGS LENGTH AND NUMBER OF PASSWORDS | |
public class PassGen | |
{ | |
private static Random rnd = new Random(); | |
public static void main(String[] args) | |
{ | |
int length = Integer.valueOf(args[0]); | |
int number = Integer.valueOf(args[1]); | |
//ArrayList<String> commands = new ArrayList(Arrays.asList(args)); | |
String[] arr = new String[number]; | |
for(int i=0;i<number;i++){ | |
arr[i] = generatePassword(length); | |
} | |
System.out.print(Arrays.asList(arr).toString()); | |
} | |
public static String generatePassword(int length){ | |
String result=""; | |
for(int i = 0; i<length;i++){ | |
char a = (char)(rnd.nextInt(94)+32); | |
result+= a; | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment