Skip to content

Commit

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

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

This comment has been minimized.

Copy link
@PetteriM1

PetteriM1 Sep 12, 2019

Member

Why double semicolon?

pk.isMainServer = this.isMainServer();
pk.description = this.serverDescription;
pk.maxPlayers = this.getSynapse().getServer().getMaxPlayers();
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/org/itxtech/nemisys/utils/Utils.java
Original file line number Diff line number Diff line change
@@ -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;

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

0 comments on commit 028aeef

Please sign in to comment.