diff --git a/src/main/java/org/itxtech/nemisys/Server.java b/src/main/java/org/itxtech/nemisys/Server.java index 54794413..21c6a32e 100644 --- a/src/main/java/org/itxtech/nemisys/Server.java +++ b/src/main/java/org/itxtech/nemisys/Server.java @@ -1,5 +1,6 @@ package org.itxtech.nemisys; +import com.google.common.hash.Hashing; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.gson.Gson; import lombok.Getter; @@ -29,6 +30,7 @@ import org.itxtech.nemisys.utils.*; import java.io.File; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.LinkedBlockingQueue; @@ -285,7 +287,7 @@ public void updateClientData() { public boolean comparePassword(String pass) { String truePass = this.getPropertyString("password", "1234567890123456"); - return Utils.md5(truePass).equals(pass); + return Hashing.md5().hashBytes(truePass.getBytes(StandardCharsets.UTF_8)).toString().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 10b0e442..2843de6e 100644 --- a/src/main/java/org/itxtech/nemisys/synapse/SynapseEntry.java +++ b/src/main/java/org/itxtech/nemisys/synapse/SynapseEntry.java @@ -1,5 +1,6 @@ package org.itxtech.nemisys.synapse; +import com.google.common.hash.Hashing; import com.google.gson.Gson; import org.itxtech.nemisys.Nemisys; import org.itxtech.nemisys.Player; @@ -11,10 +12,10 @@ 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; +import java.nio.charset.StandardCharsets; import java.util.*; /** @@ -166,7 +167,7 @@ public void connect() { this.getSynapse().getLogger().notice("Connecting " + this.getHash()); this.verified = false; ConnectPacket pk = new ConnectPacket(); - pk.password = Utils.md5(this.password); + pk.password = Hashing.md5().hashBytes(this.password.getBytes(StandardCharsets.UTF_8)).toString();; 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 8a7df673..ddb54e39 100644 --- a/src/main/java/org/itxtech/nemisys/utils/Utils.java +++ b/src/main/java/org/itxtech/nemisys/utils/Utils.java @@ -1,9 +1,7 @@ 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; /** @@ -175,16 +173,4 @@ 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); - } - } }