Search code examples
javamysqleasyphp

Java mySQL login with MD5 passwords issue


I have the following issue : I can't login with my following code : I'm not getting any sintax error but I can't get the ' loginSuccess boolean to get true. Code and table pic lower :

I've even tried the equivalent of VB.NET query- type without any success :

Dim SqlQuery As String = "SELECT COUNT(*) From users1 WHERE username = @Username AND password = MD5(@Password); "

with

resultSet = statement.executeQuery("SELECT * FROM cards.username WHERE username = '" + username + "' AND password = ('MD5(" + password + ")'");

OR

resultSet = statement.executeQuery("SELECT * FROM cards.username WHERE username = '" + username + "' AND password = MD5("' + password + ")'");

enter image description here

String sqlQuery = "select count(*) > 0 as match_found FROM username WHERE username = ? and password = MD5(?)";
// String sqlQuery = "select count(*) > 0 as cnt FROM username WHERE username = ? and password = MD5(?)";

PreparedStatement pst = connect.prepareStatement( sqlQuery );
pst.setString( 1, username );
pst.setString( 2, password );

ResultSet rs = pst.executeQuery();
boolean loginSuccess = false;
if( rs.next() ) {
  loginSuccess = rs.getBoolean( "match_found" );
  int cnt = rs.getInt(1);
  System.out.println(cnt);
}

if(loginSuccess)
    System.out.println("yess");
else
    System.out.println("noo");

Solution

  • The problem came up from my password varchar, it was 10 and the encryption didn't had enough space. Raised it to 50/100 and now I can login. Thanks