diff --git a/src/main/java/org/itxtech/nemisys/Server.java b/src/main/java/org/itxtech/nemisys/Server.java index 3ee060d9..54794413 100644 --- a/src/main/java/org/itxtech/nemisys/Server.java +++ b/src/main/java/org/itxtech/nemisys/Server.java @@ -118,7 +118,7 @@ public Server(MainLogger logger, final String filePath, String dataPath, String put("server-port", 19132); put("synapse-ip", "0.0.0.0"); put("synapse-port", 10305); - put("password", "1234567890123456"/* TODO MD5 Password*/); + put("password", "1234567890123456"); put("lang", "eng"); put("async-workers", "auto"); put("enable-profiling", false); @@ -285,7 +285,7 @@ public void updateClientData() { public boolean comparePassword(String pass) { String truePass = this.getPropertyString("password", "1234567890123456"); - return (truePass.equals(pass)); + return Utils.md5(truePass).equals(pass); } public void enablePlugins() { diff --git a/src/main/java/org/itxtech/nemisys/synapse/SynapseEntry.java b/src/main/java/org/itxtech/nemisys/synapse/SynapseEntry.java index 2a60107b..10b0e442 100644 --- a/src/main/java/org/itxtech/nemisys/synapse/SynapseEntry.java +++ b/src/main/java/org/itxtech/nemisys/synapse/SynapseEntry.java @@ -11,6 +11,7 @@ import org.itxtech.nemisys.synapse.network.SynLibInterface; import org.itxtech.nemisys.synapse.network.SynapseInterface; import org.itxtech.nemisys.utils.ClientData; +import org.itxtech.nemisys.utils.Utils; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -165,7 +166,7 @@ public void connect() { this.getSynapse().getLogger().notice("Connecting " + this.getHash()); this.verified = false; ConnectPacket pk = new ConnectPacket(); - pk.password = this.password; + pk.password = Utils.md5(this.password); pk.isMainServer = this.isMainServer(); pk.description = this.serverDescription; pk.maxPlayers = this.getSynapse().getServer().getMaxPlayers(); diff --git a/src/main/java/org/itxtech/nemisys/utils/Utils.java b/src/main/java/org/itxtech/nemisys/utils/Utils.java index ddb54e39..8a7df673 100644 --- a/src/main/java/org/itxtech/nemisys/utils/Utils.java +++ b/src/main/java/org/itxtech/nemisys/utils/Utils.java @@ -1,7 +1,9 @@ package org.itxtech.nemisys.utils; import java.io.*; +import java.math.BigInteger; import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; import java.util.UUID; /** @@ -173,4 +175,16 @@ private static int hexToBin(char ch) { if ('a' <= ch && ch <= 'f') return ch - 'a' + 10; return -1; } + + public static String md5(String s) { + try { + String md5 = new BigInteger(1, MessageDigest.getInstance("MD5").digest(s.getBytes(StandardCharsets.UTF_8))).toString(16); + for (int i = 0; i < 32 - md5.length(); i++) { + md5 = '0' + md5; + } + return md5; + } catch (Exception e) { + throw new RuntimeException(e); + } + } }