problème de authentification mot de passe crypter md5
bonsoir ,
j ai une base de donnée crée par symfony 3.4 crypter en md5
je fait identifier par java le problème je connait le login et le mot de passe mais lorsque je fait le login avec java il ne trouve pas voila mes code :
controlleur javafx
Code:
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
| @FXML
private void connexionButton(ActionEvent event) throws IOException {
LoginServices service = new LoginServices();
int x =service.Valide(usern.getText(), passw.getText());
if(x!=-1 && x!=0 && x!=-2)
{
closeStage();
Paw.session=service.getInformation(x);
ConnexionServices s=new ConnexionServices();
if(s.existe(x))
{
s.updateConnexion(x);
}
else
{
s.inserer(new Connexion(x));
}
loadMain();
}
else if ( x == 0)
{
// information fausse
messageInformationFausses();
}
else if ( x == -1)
{
// Erreur, réesseyée plus tard
messageErreur();
}
else
{
// Utilisateur bloqué
messageIsBloqued();
}
} |
fichier service login
Code:
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
|
public class LoginServices {
protected Connection connection;
public LoginServices (){
connection = MyConnexion.Get_Instance().getCon();
}
public int Valide (String usern,String passw)
{
String req="SELECT * FROM fos_user where username=? and password=?" ;
try {
PreparedStatement ste = connection.prepareStatement(req) ;
ste.setString(1,usern) ;
ste.setString(2,MD5(passw)) ;
ResultSet rs = ste.executeQuery();
if (rs.next())
{
if (rs.getString("enabled").startsWith("0"))
{
return -2;
}
else{
return rs.getInt("id");
}
}
else
{
return 0;
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
return -1;
}
}
public String MD5(String md5) {
try {
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
byte[] array = md.digest(md5.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < array.length; ++i) {
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3));
}
return sb.toString();
}
catch (java.security.NoSuchAlgorithmException e) {
}
return null;
}
} |
je teste le résulta de valide et toujours 0 merci de m aider