Skip to content

Commit

Permalink
Implement password encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
wode490390 committed Sep 11, 2019
1 parent b3a05be commit b533af4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/itxtech/nemisys/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/itxtech/nemisys/synapse/SynapseEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/itxtech/nemisys/utils/Utils.java
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit b533af4

Please sign in to comment.