UUID update and sign up verification
This commit is contained in:
parent
3c59cf1474
commit
ac08cc0f8a
@ -7,6 +7,7 @@ import org.json.simple.parser.ParseException;
|
|||||||
import org.mindrot.jbcrypt.BCrypt;
|
import org.mindrot.jbcrypt.BCrypt;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -61,6 +62,7 @@ public class SaltNic extends NanoHTTPD {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Response handleHasJoinedRequest(IHTTPSession session) {
|
private Response handleHasJoinedRequest(IHTTPSession session) {
|
||||||
|
try {
|
||||||
String uuid = UserId.generateUserId(session.getParameters().get("username").get(0));
|
String uuid = UserId.generateUserId(session.getParameters().get("username").get(0));
|
||||||
if (this.sessions.containsKey(uuid) && this.sessions.get(uuid)) {
|
if (this.sessions.containsKey(uuid) && this.sessions.get(uuid)) {
|
||||||
this.sessions.remove(uuid);
|
this.sessions.remove(uuid);
|
||||||
@ -74,6 +76,9 @@ public class SaltNic extends NanoHTTPD {
|
|||||||
" \"profileActions\" : [ ]\n" +
|
" \"profileActions\" : [ ]\n" +
|
||||||
"}");
|
"}");
|
||||||
}
|
}
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, "text/plain", "Server error");
|
return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, "text/plain", "Server error");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +95,7 @@ public class SaltNic extends NanoHTTPD {
|
|||||||
String username = (String) json.get("username");
|
String username = (String) json.get("username");
|
||||||
String password = (String) json.get("password");
|
String password = (String) json.get("password");
|
||||||
|
|
||||||
if (username == null || password == null) {
|
if (username == null || password == null || password.length() < 3 || username.length() < 3) {
|
||||||
return newFixedLengthResponse(Response.Status.BAD_REQUEST, "text/plain", "Missing username or password");
|
return newFixedLengthResponse(Response.Status.BAD_REQUEST, "text/plain", "Missing username or password");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,19 @@
|
|||||||
package com.alterdekim.xcraft.auth;
|
package com.alterdekim.xcraft.auth;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.math.BigInteger;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
public class UserId {
|
public class UserId {
|
||||||
public static String generateUserId(String username) {
|
public static String generateUserId(String username) throws NoSuchAlgorithmException {
|
||||||
return UUID.nameUUIDFromBytes(username.getBytes()).toString().replace("-", "");
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||||
|
md.update(username.getBytes());
|
||||||
|
byte[] digest = md.digest();
|
||||||
|
BigInteger bigInt = new BigInteger(1, digest);
|
||||||
|
StringBuilder hashtext = new StringBuilder(bigInt.toString(16));
|
||||||
|
while(hashtext.length() < 32 ){
|
||||||
|
hashtext.insert(0, "0");
|
||||||
|
}
|
||||||
|
return hashtext.toString().toLowerCase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user