Replaced insecure Minecraft account authentication with server join technique
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package eu.crushedpixel.replaymod.online.authentication;
|
||||
|
||||
import com.mojang.authlib.exceptions.AuthenticationException;
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.ApiClient;
|
||||
import eu.crushedpixel.replaymod.api.ApiException;
|
||||
@@ -36,10 +37,10 @@ public class AuthenticationHandler {
|
||||
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
public static void register(String usrname, String mail, String password) throws IOException, ApiException {
|
||||
public static void register(String usrname, String mail, String password)
|
||||
throws IOException, ApiException, AuthenticationException {
|
||||
AuthKey auth = apiClient.register(usrname, mail, password,
|
||||
mc.getSession().getProfile().getId().toString(),
|
||||
Minecraft.getMinecraft().getSession().getToken());
|
||||
mc.getSession().getProfile().getId().toString());
|
||||
username = usrname;
|
||||
authkey = auth.getAuthkey();
|
||||
saveAuthkey(authkey);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user