diff --git a/src/main/java/org/samo_lego/simpleauth/commands/ChangepwCommand.java b/src/main/java/org/samo_lego/simpleauth/commands/ChangepwCommand.java index fcf12d0..24b7753 100644 --- a/src/main/java/org/samo_lego/simpleauth/commands/ChangepwCommand.java +++ b/src/main/java/org/samo_lego/simpleauth/commands/ChangepwCommand.java @@ -55,6 +55,18 @@ public class ChangepwCommand { return 0; } else if (AuthHelper.checkPass(player.getUuidAsString(), oldPass.toCharArray())) { + if(newPass.length() < SimpleAuth.config.main.minPasswordChars) { + player.sendMessage(new LiteralText( + String.format(SimpleAuth.config.lang.minPasswordChars, SimpleAuth.config.main.minPasswordChars) + )); + return 0; + } + else if(newPass.length() > SimpleAuth.config.main.maxPasswordChars && SimpleAuth.config.main.maxPasswordChars != -1) { + player.sendMessage(new LiteralText( + String.format(SimpleAuth.config.lang.maxPasswordChars, SimpleAuth.config.main.maxPasswordChars) + )); + return 0; + } SimpleAuth.db.update( player.getUuidAsString(), null, diff --git a/src/main/java/org/samo_lego/simpleauth/commands/LoginCommand.java b/src/main/java/org/samo_lego/simpleauth/commands/LoginCommand.java index cf269f9..ff1900a 100644 --- a/src/main/java/org/samo_lego/simpleauth/commands/LoginCommand.java +++ b/src/main/java/org/samo_lego/simpleauth/commands/LoginCommand.java @@ -44,7 +44,6 @@ public class LoginCommand { return 0; } else if(SimpleAuth.deauthenticatedUsers.get(player) >= maxLoginTries && maxLoginTries != -1) { - SimpleAuth.deauthenticatePlayer(player); player.networkHandler.disconnect(loginTriesExceeded); return 0; } @@ -60,7 +59,6 @@ public class LoginCommand { } // Kicking the player out else if(maxLoginTries == 1) { - SimpleAuth.deauthenticatePlayer(player); player.networkHandler.disconnect(wrongPassword); return 0; } diff --git a/src/main/java/org/samo_lego/simpleauth/commands/RegisterCommand.java b/src/main/java/org/samo_lego/simpleauth/commands/RegisterCommand.java index 602fd85..519ab52 100644 --- a/src/main/java/org/samo_lego/simpleauth/commands/RegisterCommand.java +++ b/src/main/java/org/samo_lego/simpleauth/commands/RegisterCommand.java @@ -7,7 +7,6 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; import org.samo_lego.simpleauth.SimpleAuth; -import org.samo_lego.simpleauth.utils.AuthConfig; import org.samo_lego.simpleauth.utils.AuthHelper; import static com.mojang.brigadier.arguments.StringArgumentType.getString; @@ -50,6 +49,18 @@ public class RegisterCommand { return 0; } else if(pass1.equals(pass2)) { + if(pass1.length() < SimpleAuth.config.main.minPasswordChars) { + player.sendMessage(new LiteralText( + String.format(SimpleAuth.config.lang.minPasswordChars, SimpleAuth.config.main.minPasswordChars) + )); + return 0; + } + else if(pass1.length() > SimpleAuth.config.main.maxPasswordChars && SimpleAuth.config.main.maxPasswordChars != -1) { + player.sendMessage(new LiteralText( + String.format(SimpleAuth.config.lang.maxPasswordChars, SimpleAuth.config.main.maxPasswordChars) + )); + return 0; + } String hash = AuthHelper.hashPass(pass1.toCharArray()); if (SimpleAuth.db.registerUser(player.getUuidAsString(), source.getName(), hash)) { SimpleAuth.authenticatePlayer(player, registerSuccess); diff --git a/src/main/java/org/samo_lego/simpleauth/utils/AuthConfig.java b/src/main/java/org/samo_lego/simpleauth/utils/AuthConfig.java index 5dd5dc6..bb55c9a 100644 --- a/src/main/java/org/samo_lego/simpleauth/utils/AuthConfig.java +++ b/src/main/java/org/samo_lego/simpleauth/utils/AuthConfig.java @@ -66,6 +66,9 @@ public class AuthConfig { public String globalPassword = null; // Tries to rescue players if they are stuck inside a portal on logging in public boolean tryPortalRescue = true; + // Minimum and maximum length of password. Set -1 to disable max chars + public int minPasswordChars = 4; + public int maxPasswordChars = -1; } public static class LangConfig { public String enterPassword = "§6You need to enter your password!"; @@ -90,6 +93,8 @@ public class AuthConfig { public String accountDeleted = "§aYour account was successfully deleted!"; public String configurationReloaded = "§aConfiguration file was reloaded successfully."; public String successfulPortalRescue = "§aYou were rescued from nether portal successfully!"; + public String maxPasswordChars = "§6Password can be at most %d characters long!"; + public String minPasswordChars = "§6Password needs to be at least %d characters long!"; } private static final Logger LOGGER = LogManager.getLogger(); private static final Gson gson = new GsonBuilder()