1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| public class authentificationV02 extends JFrame {
private JLabel bienvenue;
private JLabel demandeid;
private JTextField champNomUtilisateur;
private JTextField champMotDePasse;
private JButton validation;
private int statutconnextion;
private JPanel jContentPane ;
public authentificationV02(){
super();
setTitle ("Authentification");
setBounds (100, 200, 200, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
bienvenue = new JLabel ("Bienvenue dans l'interface");
demandeid = new JLabel ("Veuillez vous identifier:");
champNomUtilisateur = new JTextField ("login :" );
champMotDePasse = new JTextField ("mot de passe :");
validation = new JButton ("Valider");
MyListener myListener = new MyListener();
validation.addActionListener(myListener);
validation.setSize(50,25);
Container contenu = (Container) getContentPane();
contenu.setLayout (new GridLayout(5,1,5,5));
contenu.add(bienvenue);
contenu.add(demandeid);
contenu.add(champNomUtilisateur);
contenu.add(champMotDePasse);
contenu.add(validation);
setVisible (true);
}
class MyListener implements ActionListener
{
private String testuser;
private String testmdp;
private String nom;
private String nomu;
public void actionPerformed(ActionEvent event)
{
if((JButton)event.getSource() == validation)
{
Parametres id = new Parametres();
id.setNomUtilisateur(champNomUtilisateur.getText());
id.setMotDePasse(champMotDePasse.getText());
try {
Class.forName("com.mysql.jdbc.Driver");
//String url = "jdbc:mysql://localhost/utilisateur";
String login = id.getNomUtilisateur();
String passe = id.getMotDePasse();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/utilisateur", "root", "");
if(conn != null) JOptionPane.showMessageDialog(null,"Connexion Réussie, Vérification de l'identité...");
Statement st = conn.createStatement();
String query = "SELECT * FROM users ";
ResultSet rs = st.executeQuery(query);
while (rs.next()) {
/*System.out.println("numéro:" + rs.getInt("num") );
System.out.println( "login:" + rs.getString("login"));
System.out.println( "mdp:" + rs.getString("passe"));
System.out.println( "nom:" + rs.getString("nom"));
*/
testuser= rs.getString("login");
testmdp = rs.getString("passe");
nomu = rs.getString("nom");
}
if(testuser.equals("NomUtilisateur") && testmdp.equals("MotDePasse"))
JOptionPane.showMessageDialog(null,"Bonjour monsieur " +nomu);
/*Statement st1 = conn.createStatement();
String query1 = "SELECT nom FROM users WHERE `num` = '"+nom+"'";
ResultSet rs1 = st1.executeQuery(query1);
while (rs1.next()) {
nomutil = rs1.getString("nom");
}
*/
//if(nom.equals(nom)) {
//menu v =new menu(); dispose();}
}
catch (Exception e) {
JOptionPane.showMessageDialog(null,"Exception: " +e.getMessage());
}
}
}
//@Override
/*public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}*/
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new authentificationV02();
}
});
}} |
Partager