Results 1 to 1 of 1
  1. #1
    jervis is offline Member
    Join Date
    Mar 2010
    Posts
    1
    Rep Power
    0

    Default Help me c n edit the password Genarator code !! EMERGENCY

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;

    public class passGen implements ActionListener
    {
    private JFrame f;
    private JRadioButton r1,r2,r3,r4;
    private JLabel lblLength;
    private JTextField txt,txtLength;
    private JButton gen,exit;
    private JPanel p1,p2,p3,p4;


    public passGen()
    {
    f = new JFrame("Password Generator");
    gen = new JButton("generate");
    exit = new JButton("exit");
    txt = new JTextField(10);
    lblLength = new JLabel("Enter length of password:");
    txtLength = new JTextField(10);
    r1 = new JRadioButton("UpperCase");
    r2 = new JRadioButton("LowerCase");
    r3 = new JRadioButton("Digits");
    r4 = new JRadioButton("Special characters");

    gen.addActionListener(this);
    exit.addActionListener(this);

    f.getContentPane().setLayout(new GridLayout (4,1,10,10));

    p1 = new JPanel();
    p1.setLayout(new GridLayout(1,4));
    p1.add(r1);
    p1.add(r2);
    p1.add(r3);
    p1.add(r4);
    f.getContentPane().add(p1);

    p4 = new JPanel();
    p4.setLayout(new GridLayout(1,2,10,10));
    p4.add(lblLength);
    p4.add(txtLength);
    f.getContentPane().add(p4);

    p2 = new JPanel();
    p2.setLayout(new GridLayout(1,1));
    p2.add(txt);
    f.getContentPane().add(p2);

    p3 = new JPanel();
    p3.setLayout(new FlowLayout());
    p3.add(gen);
    p3.add(exit);
    f.getContentPane().add(p3);

    f.setSize(400,400);
    f.setVisible(true);

    }

    public static int MIN_LENGTH = 0;



    protected static java. util.Random r = new java.util.Random();


    protected static char[] goodChar = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H','I', 'J', 'K',
    'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };

    protected static char [] LowChar = {'a','b','c','d','e','f','g','h','i','j','k','l',' m','n','o','p','q','r','s','t','u','v','w','x','y' ,'z' };

    protected static char [] numberChar = {'1','2','3','4','5','6','7','8','9','0'};

    protected static char [] symchar = {'!','@','#','$','%','^','&','*','(',')'};

    protected static char [] UpLowChar = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H','I', 'J', 'K',
    'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z','a','b','c','d','e','f','g','h','i','j','k','l ','m','n','o','p','q','r','s','t','u','v','w','x', 'y','z' };

    protected static char [] UpLowDigChar = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H','I', 'J', 'K',
    'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z','a','b','c','d','e','f','g','h','i','j','k','l ','m','n','o','p','q','r','s','t','u','v','w','x', 'y','z','1','2','3','4','5','6','7','8','9','0'};

    protected static char [] UpLowDigSymChar = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H','I', 'J', 'K',
    'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z','a','b','c','d','e','f','g','h','i','j','k','l ','m','n','o','p','q','r','s','t','u','v','w','x', 'y','z','1','2','3','4','5','6','7','8','9','0','! ','@','#','$','%','^','&','*','(',')'};


    public static String getNext()
    { StringBuffer sb = new StringBuffer();
    for(int i =0; i < MIN_LENGTH; i++)
    {
    sb.append(goodChar[r.nextInt(goodChar.length)]);
    }
    return sb.toString();

    }

    public static String getLow()
    {
    StringBuffer ab = new StringBuffer();
    for(int i =0; i<MIN_LENGTH; i++)
    { ab.append(LowChar [r.nextInt(LowChar.length)]);
    }
    return ab.toString();
    }

    public static String getNum()
    {
    StringBuffer cd = new StringBuffer();
    for(int i=0; i<MIN_LENGTH ; i++)
    {
    cd.append(numberChar [r.nextInt(numberChar.length)]);
    }

    return cd.toString();
    }

    public static String getSym()
    {
    StringBuffer ef = new StringBuffer();
    for (int i = 0; i<MIN_LENGTH; i++ )
    {ef.append(symchar [r.nextInt(symchar.length)]);
    }

    return ef.toString();
    }

    public static String getUpLow()
    {
    StringBuffer gh = new StringBuffer();
    for(int i=0; i<MIN_LENGTH; i++)
    { gh.append(UpLowChar [r.nextInt(UpLowChar.length)]);}

    return gh.toString();
    }

    public static String getUpLowDig()
    {
    StringBuffer ij = new StringBuffer();
    for(int i=0; i<MIN_LENGTH; i++)
    {ij.append(UpLowDigChar [r.nextInt(UpLowDigChar.length)]);}

    return ij.toString();
    }

    public static String getUpLowDigSym()
    {
    StringBuffer kl = new StringBuffer();
    for(int i =0; i<MIN_LENGTH; i++)
    {kl.append(UpLowDigSymChar [r.nextInt(UpLowDigSymChar.length)]);}

    return kl.toString();
    }
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource() == gen)
    {
    int length;

    length = Integer.parseInt(txtLength.getText());


    MIN_LENGTH = length;




    if(r1.isSelected())
    {
    txt.setText(passGen.getNext());
    }

    else if(r2.isSelected())
    {
    txt.setText(passGen.getLow());
    }

    else if (r3.isSelected())
    {

    txt.setText(passGen.getNum());
    }

    else if (r4.isSelected())
    {

    txt.setText(passGen.getSym());
    }

    if(r1.isSelected() && r2.isSelected())
    {
    txt.setText(passGen.getUpLow());
    }

    if(r1.isSelected() && r2.isSelected() && r3.isSelected())
    {
    txt.setText(passGen.getUpLowDig());
    }

    if(r1.isSelected() && r2.isSelected() && r3.isSelected() && r4.isSelected())
    {
    txt.setText(passGen.getUpLowDigSym());
    }
    }
    else
    {
    System.exit(0);
    }

    }
    public static void main( String args[])
    {
    passGen app = new passGen();
    }
    }


    ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++

    problem
    1. upper case n lower case cant mix wit symbol and digits.
    2. if i wan create a textfiled let user key in the special symbol and add on the symbol to the genaraotor for generate.

    anyone help me pls..reli EMERGENCY..tat is my final project..i m stucking..pls help me..thx alot..
    Last edited by jervis; 03-28-2010 at 11:52 AM.

Similar Threads

  1. Online IDE to edit and compile code?
    By DarrenReeder in forum Other IDEs
    Replies: 1
    Last Post: 02-06-2011, 01:58 AM
  2. Edit a .jar?
    By JuBe in forum New To Java
    Replies: 4
    Last Post: 09-15-2009, 11:07 PM
  3. how to check password for 3 times enterd wrong password
    By sk.mahaboobbhasha@gmail.c in forum New To Java
    Replies: 2
    Last Post: 11-14-2008, 07:53 PM
  4. how to check password for 3 times enterd wrong password
    By sk.mahaboobbhasha@gmail.c in forum Java Servlet
    Replies: 0
    Last Post: 11-14-2008, 01:22 PM
  5. How to check password of a jsp/html with the password of Database(mysql) #1
    By sk.mahaboobbhasha@gmail.c in forum Java Servlet
    Replies: 2
    Last Post: 11-14-2008, 01:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •