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 117 118 119 120 121 122
| public class authentification extends JFrame{
private final JLabel loginLabel = new JLabel();
private final JLabel passwordLabel = new JLabel();
private final JTextField textField = new JTextField();
private final JPasswordField passwordField = new JPasswordField();
private final JButton okButton = new JButton();
private final JButton exitButton = new JButton();
public String Login;
public String login2;
public authentification() {
super();
//textField.setText("admin");
login2=textField.getText();
try {
jbInit();
} catch (Throwable e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
setTitle("Login");
getContentPane().add(loginLabel);
loginLabel.setText("Login");
loginLabel.setBounds(95, 60, 66, 16);
getContentPane().add(passwordLabel);
passwordLabel.setText("Password");
passwordLabel.setBounds(95, 114, 66, 16);
getContentPane().add(textField);
textField.setBounds(179, 58, 112, 20);
getContentPane().add(passwordField);
passwordField.setBounds(179, 112, 112, 20);
getContentPane().add(okButton);
okButton.addActionListener(new OkButtonActionListener());
okButton.setText("OK");
okButton.setBounds(371, 164, 97, 26);
getContentPane().add(exitButton);
exitButton.setText("Exit");
exitButton.setBounds(257, 164, 106, 26);
}
private class OkButtonActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
okButton_actionPerformed(e);
}
}
protected void okButton_actionPerformed(ActionEvent e) {
try{
Class.forName("org.postgresql.Driver");
//System.out.println("DRIVER OK ! ");
String url = "jdbc:postgresql://localhost:5432/postgis";
String user = "postgres";
String passwd = "root";
Connection conn = DriverManager.getConnection(url, user, passwd);
Statement state2 = conn.createStatement();
ResultSet result = state2.executeQuery("SELECT \"login\" , \"pwd\" FROM users where \"login\" like '"+textField.getText()+"'");
ResultSetMetaData resultMeta = result.getMetaData();
if(result.next()){
//for(int i = 1; i <= resultMeta.getColumnCount(); i++)
if ( result.getString("pwd").equals(passwordField.getText()))
{
NotesJFrame notesJFrame = new NotesJFrame();
notesJFrame.setVisible(true);
notesJFrame.setLocationRelativeTo(null);
login2=(result.getString("login"));
}
else
{
JOptionPane jop3 = new JOptionPane();
jop3.showMessageDialog(null, "Mot de passe incorrect !", "Erreur", JOptionPane.ERROR_MESSAGE);
}
}
else
{
JOptionPane jop3 = new JOptionPane();
jop3.showMessageDialog(null, "Login incorrect !", "Erreur", JOptionPane.ERROR_MESSAGE);
}
result.close();
state2.close();
} catch (Exception e1) {
e1.printStackTrace();
}
login2=textField.getText();
}
public String getNom()
{
return login2;
}
} |
Partager