|
package Graphic;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JPasswordGen {
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'};
char num[] = {'1','2','3','4','5','6','7','8','9','0'};
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'};
char special[] = {'è','+','ò','à','ù',',','.','-',';',':','_','ç','°','§','é','*','^','?','=','(',')','/','&','%','$','£','!','|','@','#','[',']'};
public static void main (String[] args ) {
new JPasswordGen();
}
JPasswordGen(){
JFrm.setContentPane(JPnl);
JFrm.setSize(350,250);
int x = (sS.width - JFrm.getWidth()) / 2;
int y = (sS.height - JFrm.getHeight()) / 2;
JFrm.setLocation(x,y);
JFrm.setResizable(false);
JFrm.pack();
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");
final String Lenght = JOptionPane. showInputDialog(JFrm, "Inserire la lunghezza della password da generare:", "9");
}
});
GenPwd(Case,Lenght,JPwd);
}
});
JFrm.setVisible(true);
GenPwd(Case,Lenght,JPwd);
}
if(Tipo.equals("1")){
for(int i = 0;i<Integer.parseInt(Lunghezza);i++) {
int c = (int) (Math. random() * num. length);
Str += num[c];
}
JPwd.setText(Str);
}else if (Tipo.equals("2")){
for(int i = 0;i<Integer.parseInt(Lunghezza);i++) {
int c = (int) (Math. random() * alfa. length);
Str += alfa[c];
}
JPwd.setText(Str);
}else if (Tipo.equals("3")){
for(int i = 0;i<Integer.parseInt(Lunghezza);i++) {
int c = (int) (Math. random() * alfanum. length);
Str += alfanum[c];
}
JPwd.setText(Str);
}else if (Tipo.equals("4")){
for(int i = 0;i<Integer.parseInt(Lunghezza);i++) {
int c = (int) (Math. random() * special. length);
Str += special[c];
}
JPwd.setText(Str);
}
}
}
|
|