Replaced insecure Minecraft account authentication with server join technique

This commit is contained in:
CrushedPixel
2015-05-27 13:35:44 +02:00
parent f0f0f1aa86
commit 2744e7cf6c
6 changed files with 75 additions and 6 deletions

View File

@@ -0,0 +1,44 @@
package eu.crushedpixel.replaymod.online.authentication;
import net.minecraft.client.Minecraft;
import java.util.Random;
public class AuthenticationHash {
private static final Random random = new Random();
public AuthenticationHash() {
username = Minecraft.getMinecraft().getSession().getUsername();
currentTime = System.currentTimeMillis();
randomLong = random.nextLong();
hash = getAuthenticationHash();
}
public final String username;
public final long currentTime;
public final long randomLong;
public final String hash;
private String getAuthenticationHash() {
StringBuilder builder = new StringBuilder();
builder.append(username);
builder.append(currentTime);
builder.append(randomLong);
String md5 = builder.toString();
try {
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
byte[] array = md.digest(md5.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < array.length; ++i) {
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3));
}
return sb.toString();
} catch (java.security.NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
}