[Source]Random Password Generator[Source]

Discussion in 'Programming General' started by Jimmy, Aug 20, 2009.

[Source]Random Password Generator[Source]
  1. Unread #1 - Aug 20, 2009 at 10:19 PM
  2. Jimmy
    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    [Source]Random Password Generator[Source]

    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)]'
     
  3. Unread #2 - Aug 22, 2009 at 2:39 AM
  4. super_
    Joined:
    Dec 20, 2008
    Posts:
    91
    Referrals:
    0
    Sythe Gold:
    0

    super_ Member

    [Source]Random Password Generator[Source]

    learn what a constant is. also, learn what a charset is.
     
  5. Unread #3 - Aug 26, 2009 at 7:11 PM
  6. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    [Source]Random Password Generator[Source]

    Please never use names like i1 and i2 as your loop variables ever again. A small part of me dies.
     
  7. Unread #4 - Aug 27, 2009 at 7:38 PM
  8. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    [Source]Random Password Generator[Source]

    I use a,b,c,d... And on. Lol.
     
< Client Error | Visual Basic or VB.Net >

Users viewing this thread
1 guest


 
 
Adblock breaks this site