Sécuriser une application java

Signaler
Messages postés
55
Date d'inscription
mercredi 14 avril 2010
Statut
Membre
Dernière intervention
21 décembre 2010
-
Messages postés
2814
Date d'inscription
mardi 15 avril 2003
Statut
Membre
Dernière intervention
2 juin 2020
-
bonjours mes amis;

j'ai un problème de l'exécution de login et mot de passe.
le problème est n'importe qui peut accéder à mon application l'application ne vérifier pas le login et le mot de passe et voila mon code



////////////////////////////////////////////////////////////////////////
//LoginForm.java
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.UnknownHostException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;


import javax.imageio.IIOException;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.border.Border;


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

public class LoginForm extends JFrame {

// Variables declaration
private JLabel jLabel1;
private JLabel jLabel2,jLabel3;
private JTextField jTextField1;
private JComboBox l3=null;
private JPasswordField jPasswordField1;
private JButton jButton1;
private JPanel contentPane;
boolean loop = false;
// End of variables declaration

public LoginForm() {
super();
create();
this.setVisible(true);
}

private void create() {
jLabel1 = new JLabel();
jLabel2 = new JLabel();
jLabel3 = new JLabel();
jTextField1 = new JTextField();
jPasswordField1 = new JPasswordField();
l3=new JComboBox();
l3.addItem("Administrateur");
l3.addItem("Non administrateur");
jButton1 = new JButton();
contentPane = (JPanel)this.getContentPane();

//
// jLabel1
//
jLabel1.setHorizontalAlignment(SwingConstants.LEFT);
jLabel1.setForeground(new Color(0, 0, 255));
jLabel1.setText("Login :");
//
// jLabel2
//
jLabel2.setHorizontalAlignment(SwingConstants.LEFT);
jLabel2.setForeground(new Color(0, 0, 255));
jLabel2.setText("Mot de passe :");
//

// jLabel2
//
jLabel3.setHorizontalAlignment(SwingConstants.LEFT);
jLabel3.setForeground(new Color(0, 0, 255));
jLabel3.setText("Etat :");
//

// jTextField1
//
jTextField1.setForeground(new Color(0, 0, 255));
jTextField1.setSelectedTextColor(new Color(0, 0, 255));
jTextField1.setToolTipText("Entrer votre login");

//
// jPasswordField1
//
jPasswordField1.setForeground(new Color(0, 0, 255));
jPasswordField1.setToolTipText("Entrer votre mot de passe");

//


// jTextField1
//
l3.setForeground(new Color(0, 0, 255));
l3.setSelectedItem(new Color(0, 0, 255));
l3.setToolTipText("login");

//


// jButton1
//
jButton1.setBackground(new Color(204, 204, 204));
jButton1.setForeground(new Color(0, 0, 255));
jButton1.setText("OK");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
actionPerformed(e);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}

});

//
// contentPane
//
contentPane.setLayout(null);
contentPane.setBorder(BorderFactory.createEtchedBorder());
contentPane.setBackground(new Color(204, 204, 204));
addComponent(contentPane, jLabel1, 5,10,106,18);
addComponent(contentPane, jLabel2, 5,47,97,18);
addComponent(contentPane, jLabel3, 5,77,90,18);
addComponent(contentPane, jTextField1, 110,10,183,22);
addComponent(contentPane, jPasswordField1, 110,45,183,22);

addComponent(contentPane, l3, 110,75,183,22);

addComponent(contentPane, jButton1, 150,100,25,28);

//
// login
//
this.setTitle("Espace d'authentification");
this.setLocation(new Point(76, 182));
this.setSize(new Dimension(345, 251));
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setResizable(false);
} //end of create()

/** Add Component Without a Layout Manager (Absolute Positioning) */
private void addComponent(Container container,Component c,int x,int y,int width,int height) {
c.setBounds(x,y,width,height);
container.add(c);
} //end of addComponent()

private void jLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jLoginActionPerformed
boolean connected = false;
try {
new ConnectDB("jdbc:mysql://localhost:3306/eracontacttt","com.mysql.jdbc.Driver","root");
connected = true;

} catch(Exception ee) {
ee.toString(); }
if (connected) {
try
{


String sql1="SELECT password FROM membre WHERE username = '" + jTextField1.getText()+"' and rôle='"+l3.getSelectedItem().toString()+"'" ;
//System.out.println(sql1);
Statement statement = ConnectDB.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet resultat =(ResultSet) statement.executeQuery(sql1);

String password=null ;

while(resultat.next()) {
password =resultat.getString(1);
//System.out.println(password);
// System.out.println(jPassword.getText());
}
if (password.equals(jPasswordField1.getText()))
{
this.setVisible(false);
if(l3.getSelectedItem().toString().equals("Administrateur"))
{

new ZFenetre().setVisible(true);
}
else
{
if(l3.getSelectedItem().toString().equals("non administrateur"))
{
new Ofenetre().setVisible(true);

}


}

}
else
{
// error.message_erreur("Verifier vos paramètre ");
jPasswordField1.setText("");
jTextField1.setText("");
}
}
catch(SQLException e)
{
// error.message_erreur(e.getMessage());
}



}


// TODO add your handling code here:
}//GEN-LAST:event_jLoginActionPerformed


public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
//ZFenetre zFen = new ZFenetre();
liste_ouvrier lf = new liste_ouvrier();

add_ouv add = new add_ouv();

Liste_formation form = new Liste_formation();
// ajout_formation ajou = new ajout_formation();
Liste_process proc = new Liste_process();
ajout_process ajoutt = new ajout_process();
//liste_planifier plan = new liste_planifier();
// planifier plani = new planifier();

try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} //end of try

catch (Exception ex) {
//System.out.println("Failed loading L&F: ");
//System.out.println(ex);
} //end of catch

new LoginForm();
}; //end of main()

} //end of LoginForm
///////////////////////////////////////////////////////////////////
et merci d'avance

1 réponse

Messages postés
2814
Date d'inscription
mardi 15 avril 2003
Statut
Membre
Dernière intervention
2 juin 2020
36
Accueil > Forum > ASP / ASP3 > Base de données > MySQL > sécuriser une application java


commence par poster sur le bon forum, t'es sur aspfr ici (ASP.Net), vas sur java

Si le déboguage est l'art d'enlever les bogues, la programmation doit être l'art de les créer.