My Simple Random Password Generator
Posted: Sat Mar 09, 2013 1:19 pm
				
				Hi
After a long time I've wrote a Java program for fun 
 
I couldn't study Java for more than 6 months now because of BIT studies and etc..
This time I didn't use any IDEs just used Notepad++ and Command Prompt 
 
Here is a screenshot of my program to make my this post look good Anyway here you go. I also made a .Jar file too so everyone can download and run without compiling.
 
Anyway here you go. I also made a .Jar file too so everyone can download and run without compiling.   
 
RandomPass.java
PassGen.java
Here is the .jar file (Since .jar extension isn't allowed, I've added it into a .zip file   Extract it and use it
 Extract it and use it   )
Hope you'll get any use of it
  )
Hope you'll get any use of it    
 
Thanks
			After a long time I've wrote a Java program for fun
 
 I couldn't study Java for more than 6 months now because of BIT studies and etc..
This time I didn't use any IDEs just used Notepad++ and Command Prompt
 
 Here is a screenshot of my program to make my this post look good
 Anyway here you go. I also made a .Jar file too so everyone can download and run without compiling.
 
Anyway here you go. I also made a .Jar file too so everyone can download and run without compiling.   
 RandomPass.java
Code: Select all
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.FlowLayout;
import javax.swing.*;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
public class RandomPass extends JFrame{
	JButton generate = new JButton("Generate Password");
	JButton copy = new JButton("Copy Password");
	JTextField output = new JTextField("No Password",10);
	public RandomPass(){
		super("Random Password generator");
		JFrame frame = new JFrame();
		frame.setSize(300,110);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setLayout(new FlowLayout());
		frame.add(output);
		frame.add(generate);
		frame.add(copy);
		generate.addActionListener(new Handler());
		copy.addActionListener(new Handler());
	}
	public static void main(String args[]){
		RandomPass RP = new RandomPass();
	}
	
	private class Handler implements ActionListener{
		
		PassGen passgen = new PassGen();
		public void actionPerformed(ActionEvent e){
			if(e.getSource() == generate){
				output.setText(passgen.getRandomPass());
			}else{
				String str = output.getText();
				Toolkit toolkit = Toolkit.getDefaultToolkit();
				Clipboard clipboard = toolkit.getSystemClipboard();
				StringSelection strSel = new StringSelection(str);
				clipboard.setContents(strSel, null);
				JOptionPane.showMessageDialog(null,"Copied to Clipboard");
			}
		}
	}
}
Code: Select all
import java.util.Random;
public class PassGen{ //This class generates the password
	
	Random randomNo = new Random();
	
	private int intGenerate(){ //This generates numbers
		return randomNo.nextInt(1000000);
	}
	
	private String alphabetGenerate(){ //This generates letters
	
		String alphabet ="abcdefghijklmnopqrstuvwxyz";
		String leters = 
		""+alphabet.charAt(randomNo.nextInt(26))
		+""+alphabet.charAt(randomNo.nextInt(26))
		+""+alphabet.charAt(randomNo.nextInt(26))
		+""+alphabet.charAt(randomNo.nextInt(26))
		+""+alphabet.charAt(randomNo.nextInt(26));
		
		return leters;
	}
	
	// This Randomize the numbers and the letters and returns the new randomized password
	public String getRandomPass(){ 
		
		int part1 = intGenerate();
		String part2 = alphabetGenerate();
		
		if(randomNo.nextBoolean()){
			return "" + part1 + part2; 
		}else{
			return part2+part1;
		}
	}
}
 Extract it and use it
 Extract it and use it   )
Hope you'll get any use of it
  )
Hope you'll get any use of it    
 Thanks
