Added option for limiting password length.

This commit is contained in:
samo_lego 2020-04-12 16:11:14 +02:00
parent c4ca8ca18f
commit 9af4995fdc
4 changed files with 29 additions and 3 deletions

View File

@ -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,

View File

@ -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;
}

View File

@ -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);

View File

@ -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()