i have encrypted some login credentials in mysql database using md5, now i want what i input as login credentials to be encrypted automatically to ease comparison with the encryption in database:
This is how far i have done, no errors bt i cant login anymore
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/PMS","root","");
stmt=con.createStatement();
String value1=userfield.getText();
String value2=passfield.getText();
// the code to encrypt what i input
try
{
MessageDigest md5Encrypt = MessageDigest.getInstance("MD5");
md5Encrypt.update(value1.getBytes(), 0, value1.length());
md5Encrypt.update(value2.getBytes(), 0, value2.length());
value1 = new BigInteger(1, md5Encrypt.digest()).toString(32);
value2 = new BigInteger(1, md5Encrypt.digest()).toString(32);
}
catch (Exception exception)
{
exception.printStackTrace();
}
String Euser1=value1;
String Epass2=value2;
String user1=null;
String pass1=null;
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM login where Username= '"+Euser1+"' && Password='"+Euser1+"'");
while (rs.next())
{
user1 = rs.getString("username");
pass1 = rs.getString("password");
}
// comparison with database login data
if (Euser1.equals(user1)&& Euser1.equals(pass1) )
{
Toolkit.getDefaultToolkit().beep();
JOptionPane.showMessageDialog(null,"<html><b>User Authenticated!\n<html><i>You are Now Logged on, Press Okay To Continue.");
}
else
{
userfield.setText("");
passfield.setText("");
Toolkit.getDefaultToolkit().beep();
Thread.sleep(pause);
Toolkit.getDefaultToolkit().beep();
Thread.sleep(pause);
Toolkit.getDefaultToolkit().beep();
JOptionPane.showMessageDialog(null, "<html><b>Wrong password & username. Try again.",
"PMS Error Message", JOptionPane.ERROR_MESSAGE);
}
}
catch(Exception ex)
{
Toolkit.getDefaultToolkit().beep();
JOptionPane.showMessageDialog(null, ex,
"PMS Error Message", JOptionPane.ERROR_MESSAGE);
//System.out.println(ex.getMessage());
}
please save me.