• Log in or sign up for an account here: https://www.sythe.org/login

[Source]Random Password Generator[Source]

Jimmy

Ghost

Retired Sectional Moderator
$5 USD Donor
Joined
Jun 24, 2008
Sythe Gold
25
Messages
2,421
Location
Psychocyberspace
Not too active here. Little thing I made in a few minutes to generate peudo-random passwords. Enjoy.

Code:
import java.util.*;
import java.security.*;

class PasswordGenerator {

    public static String alph = "abcdefghijklmnopqrstuvwxyz";

    public static void main(String[] args) {
	if(args.length == 2) {
		int length = 0;
		int times = 0;

		try {
			length = Integer.parseInt(args[0]);
			times = Integer.parseInt(args[1]);
		} catch (RuntimeException e) {
			System.out.println("Invalid args! Type 'java PasswordGenerator --help' for help");
		}

		for(int i1=0; i1<times; i1++) {
			SecureRandom random = new SecureRandom();
			StringBuilder builder = new StringBuilder();
			for(int i2=0; i2<length; i2++) {
				int rand = random.nextInt(2);
				switch(rand) {
					case 0:
						builder.append((random.nextInt(10)));
						break;
					case 1:
						builder.append(((random.nextInt(2) == 0) ? (Character.toString(alph.charAt(random.nextInt(24)))).toUpperCase().toCharArray()[0] : (Character.toString(alph.charAt(random.nextInt(24)))).toLowerCase().toCharArray()[0]));
						break;
				}
			}

			System.out.println("Password" + '[' + i1 + ']' + ": " + builder.toString());
		}
	} else if((args.length == 1) && args[0].equals("--help")) {
		System.out.println("Usage: java PasswordGenerator [length] [number]" + '\n' + 
			"	(Integer) length: The length each password should be" + '\n' +
			"	(Integer) number: The number of passwords to generate"
		);
	} else {
		System.out.println("Invalid args! Type 'java PasswordGenerator --help' for help");
	}
    }

}
NOTE: The way to use this should be obvious, but if it's not, the proper usage is 'java PasswordGenerator [length (The length your password should be)] [number (the number of passwords to generate)]'
 
Please never use names like i1 and i2 as your loop variables ever again. A small part of me dies.
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
Please never use names like i1 and i2 as your loop variables ever again. A small part of me dies.

I use a,b,c,d... And on. Lol.
 
Runescape Gamblingrunescape gambling
Back
Top