Cleanup; hope to fix #18

This commit is contained in:
samo_lego 2020-09-12 16:45:14 +02:00
parent fa55b70ff2
commit e0d0a062f6
4 changed files with 10 additions and 22 deletions

View File

@ -72,7 +72,7 @@ public class AccountCommand {
// Different thread to avoid lag spikes
THREADPOOL.submit(() -> {
if (AuthHelper.checkPass(convertUuid(player), pass.toCharArray()) == 1) {
if (AuthHelper.checkPassword(convertUuid(player), pass.toCharArray()) == 1) {
DB.deleteUserData(convertUuid(player));
player.sendMessage(
new LiteralText(config.lang.accountDeleted),
@ -103,7 +103,7 @@ public class AccountCommand {
}
// Different thread to avoid lag spikes
THREADPOOL.submit(() -> {
if (AuthHelper.checkPass(convertUuid(player), oldPass.toCharArray()) == 1) {
if (AuthHelper.checkPassword(convertUuid(player), oldPass.toCharArray()) == 1) {
if (newPass.length() < config.main.minPasswordChars) {
player.sendMessage(new LiteralText(
String.format(config.lang.minPasswordChars, config.main.minPasswordChars)

View File

@ -40,7 +40,7 @@ public class LoginCommand {
// Putting rest of the command in different thread to avoid lag spikes
THREADPOOL.submit(() -> {
int maxLoginTries = config.main.maxLoginTries;
int passwordResult = AuthHelper.checkPass(uuid, pass.toCharArray());
int passwordResult = AuthHelper.checkPassword(uuid, pass.toCharArray());
if(playerCacheMap.get(uuid).loginTries >= maxLoginTries && maxLoginTries != -1) {
player.networkHandler.disconnect(new LiteralText(config.lang.loginTriesExceeded));

View File

@ -79,9 +79,8 @@ public class PlayerCache {
this.lastAir = 300;
}
if(DB.isUserRegistered(uuid)) {
String data = DB.getData(uuid);
String data = DB.getData(uuid);
if(!data.isEmpty()) {
// Getting (hashed) password
JsonObject json = gson.fromJson(data, JsonObject.class);
JsonElement passwordElement = json.get("password");

View File

@ -22,7 +22,7 @@ public class AuthHelper {
* @param password password that needs to be checked
* @return 1 for pass, 0 if password is false, -1 if user is not yet registered
*/
public static int checkPass(String uuid, char[] password) {
public static int checkPassword(String uuid, char[] password) {
if(config.main.enableGlobalPassword) {
// We have global password enabled
return verifyPassword(password, config.main.globalPassword) ? 1 : 0;
@ -30,23 +30,12 @@ public class AuthHelper {
else {
String hashed;
// Password from cache
if(playerCacheMap.containsKey(uuid))
if(playerCacheMap.get(uuid).isRegistered)
hashed = playerCacheMap.get(uuid).password;
else
return -1;
// Hashed password from DB
else {
JsonObject json = parser.parse(SimpleAuth.DB.getData(uuid)).getAsJsonObject();
JsonElement passwordElement = json.get("password");
if(passwordElement instanceof JsonNull) {
// This shouldn't have happened, data seems to be corrupted
return -1;
}
else {
hashed = passwordElement.getAsString();
}
}
if(hashed == null)
if(hashed.isEmpty())
return -1; // User is not yet registered
// Verify password