diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 24b287774..98bbaa68b 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -320,22 +320,28 @@ public class MySQL implements DataSource { @Override public boolean saveAuth(PlayerAuth auth) { try (Connection con = getConnection()) { - String sql; + // TODO ljacqu 20171104: Replace with generic columns util to clean this up boolean useSalt = !col.SALT.isEmpty() || !StringUtils.isEmpty(auth.getPassword().getSalt()); - sql = "INSERT INTO " + tableName + "(" + boolean hasEmail = auth.getEmail() != null; + String emailPlaceholder = hasEmail ? "?" : "DEFAULT"; + + String sql = "INSERT INTO " + tableName + "(" + col.NAME + "," + col.PASSWORD + "," + col.REAL_NAME + "," + col.EMAIL + "," + col.REGISTRATION_DATE + "," + col.REGISTRATION_IP + (useSalt ? "," + col.SALT : "") - + ") VALUES (?,?,?,?,?,?" + (useSalt ? ",?" : "") + ");"; + + ") VALUES (?,?,?," + emailPlaceholder + ",?,?" + (useSalt ? ",?" : "") + ");"; try (PreparedStatement pst = con.prepareStatement(sql)) { - pst.setString(1, auth.getNickname()); - pst.setString(2, auth.getPassword().getHash()); - pst.setString(3, auth.getRealName()); - pst.setString(4, auth.getEmail()); - pst.setObject(5, auth.getRegistrationDate()); - pst.setString(6, auth.getRegistrationIp()); + int index = 1; + pst.setString(index++, auth.getNickname()); + pst.setString(index++, auth.getPassword().getHash()); + pst.setString(index++, auth.getRealName()); + if (hasEmail) { + pst.setString(index++, auth.getEmail()); + } + pst.setObject(index++, auth.getRegistrationDate()); + pst.setString(index++, auth.getRegistrationIp()); if (useSalt) { - pst.setString(7, auth.getPassword().getSalt()); + pst.setString(index++, auth.getPassword().getSalt()); } pst.executeUpdate(); } diff --git a/src/main/java/fr/xephi/authme/security/crypts/PhpBB.java b/src/main/java/fr/xephi/authme/security/crypts/PhpBB.java index 4e618e241..8192306fc 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/PhpBB.java +++ b/src/main/java/fr/xephi/authme/security/crypts/PhpBB.java @@ -147,10 +147,7 @@ public class PhpBB implements EncryptionMethod { } private static boolean phpbb_check_hash(String password, String hash) { - if (hash.length() == 34) { - return _hash_crypt_private(password, hash).equals(hash); - } - return md5(password).equals(hash); + return _hash_crypt_private(password, hash).equals(hash); } } }