Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
JPasswordGen - JPasswordGen.java

JPasswordGen.java

Caricato da:
Scarica il programma completo

  1. package Graphic;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import javax.swing.*;
  5.  
  6. public class JPasswordGen {
  7.        
  8.         char alfanum[] = {'1','2','3','4','5','6','7','8','9','0','q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m','Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M'};
  9.         char num[] = {'1','2','3','4','5','6','7','8','9','0'};
  10.         char alfa[] = {'q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m','Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M'};
  11.         char special[] = {'è','+','ò','à','ù',',','.','-',';',':','_','ç','°','§','é','*','^','?','=','(',')','/','&','%','$','£','!','|','@','#','[',']'};
  12.        
  13.         public static void main(String[] args) {
  14.        new JPasswordGen();
  15.         }
  16.        
  17.          JPasswordGen(){
  18.        JFrame JFrm = new JFrame("JPasswordGen");
  19.        JPanel JPnl = new JPanel(new BorderLayout());
  20.        JButton JGen = new JButton("Genera Password!");
  21.        JButton JEsc = new JButton("Esci");
  22.        JLabel JLbl = new JLabel("Password Generata:");
  23.        final JTextField JPwd = new JTextField(15);
  24.        JPnl.setBorder(BorderFactory.createEmptyBorder(20, 20,20, 20));
  25.            JFrm.setContentPane(JPnl);
  26.            JFrm.setSize(350,250);
  27.            JPnl.add(JLbl,BorderLayout.NORTH);
  28.            JPnl.add(JPwd,BorderLayout.WEST);
  29.            JPnl.add(JEsc,BorderLayout.SOUTH);
  30.            JPnl.add(JGen,BorderLayout.EAST);
  31.            Toolkit Tk = Toolkit.getDefaultToolkit();  
  32.            Dimension sS = Tk.getScreenSize();
  33.            int x = (sS.width - JFrm.getWidth()) / 2;
  34.            int y = (sS.height - JFrm.getHeight()) / 2;
  35.            JFrm.setLocation(x,y);
  36.            JFrm.setResizable(false);
  37.            JFrm.pack();
  38.            JFrm.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  39.            final String Case = JOptionPane.showInputDialog(JFrm, "Tipo di password da generare:\n" + "1: Numerica\n" + "2: Letterale\n" + "3: Alfanumerica\n" + "4: Caratteri speciali", "3");
  40.            final String Lenght = JOptionPane.showInputDialog(JFrm, "Inserire la lunghezza della password da generare:","9");
  41.            JEsc.addActionListener(new ActionListener(){
  42.                 public void actionPerformed(ActionEvent e) {
  43.                         System.exit(0);
  44.            }
  45.            });
  46.            JGen.addActionListener(new ActionListener(){
  47.                         public void actionPerformed(ActionEvent e) {
  48.                 GenPwd(Case,Lenght,JPwd);
  49.                    }
  50.                    });
  51.            JFrm.setVisible(true);
  52.            GenPwd(Case,Lenght,JPwd);
  53.          }
  54.           public void GenPwd(String Tipo,String Lunghezza,JTextField JPwd){
  55.                         if(Tipo.equals("1")){
  56.                                 String Str = new String();
  57.                                    for(int i = 0;i<Integer.parseInt(Lunghezza);i++) {
  58.                                            int c = (int) (Math.random() * num.length);
  59.                                            Str += num[c];
  60.                                    }
  61.                                    JPwd.setText(Str);
  62.                         }else if (Tipo.equals("2")){
  63.                                 String Str = new String();
  64.                                    for(int i = 0;i<Integer.parseInt(Lunghezza);i++) {
  65.                                            int c = (int) (Math.random() * alfa.length);
  66.                                            Str += alfa[c];
  67.                                    }
  68.                                    JPwd.setText(Str);
  69.                         }else if (Tipo.equals("3")){
  70.                                 String Str = new String();
  71.                                    for(int i = 0;i<Integer.parseInt(Lunghezza);i++) {
  72.                                            int c = (int) (Math.random() * alfanum.length);
  73.                                            Str += alfanum[c];
  74.                                    }
  75.                                    JPwd.setText(Str);
  76.                         }else if (Tipo.equals("4")){
  77.                                 String Str = new String();
  78.                                    for(int i = 0;i<Integer.parseInt(Lunghezza);i++) {
  79.                                            int c = (int) (Math.random() * special.length);
  80.                                            Str += special[c];
  81.                                    }
  82.                                    JPwd.setText(Str);      
  83.                         }
  84.                 }
  85.    }