Added option for limiting password length.
This commit is contained in:
parent
c4ca8ca18f
commit
9af4995fdc
|
@ -55,6 +55,18 @@ public class ChangepwCommand {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (AuthHelper.checkPass(player.getUuidAsString(), oldPass.toCharArray())) {
|
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(
|
SimpleAuth.db.update(
|
||||||
player.getUuidAsString(),
|
player.getUuidAsString(),
|
||||||
null,
|
null,
|
||||||
|
|
|
@ -44,7 +44,6 @@ public class LoginCommand {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if(SimpleAuth.deauthenticatedUsers.get(player) >= maxLoginTries && maxLoginTries != -1) {
|
else if(SimpleAuth.deauthenticatedUsers.get(player) >= maxLoginTries && maxLoginTries != -1) {
|
||||||
SimpleAuth.deauthenticatePlayer(player);
|
|
||||||
player.networkHandler.disconnect(loginTriesExceeded);
|
player.networkHandler.disconnect(loginTriesExceeded);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +59,6 @@ public class LoginCommand {
|
||||||
}
|
}
|
||||||
// Kicking the player out
|
// Kicking the player out
|
||||||
else if(maxLoginTries == 1) {
|
else if(maxLoginTries == 1) {
|
||||||
SimpleAuth.deauthenticatePlayer(player);
|
|
||||||
player.networkHandler.disconnect(wrongPassword);
|
player.networkHandler.disconnect(wrongPassword);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import org.samo_lego.simpleauth.SimpleAuth;
|
import org.samo_lego.simpleauth.SimpleAuth;
|
||||||
import org.samo_lego.simpleauth.utils.AuthConfig;
|
|
||||||
import org.samo_lego.simpleauth.utils.AuthHelper;
|
import org.samo_lego.simpleauth.utils.AuthHelper;
|
||||||
|
|
||||||
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
||||||
|
@ -50,6 +49,18 @@ public class RegisterCommand {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if(pass1.equals(pass2)) {
|
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());
|
String hash = AuthHelper.hashPass(pass1.toCharArray());
|
||||||
if (SimpleAuth.db.registerUser(player.getUuidAsString(), source.getName(), hash)) {
|
if (SimpleAuth.db.registerUser(player.getUuidAsString(), source.getName(), hash)) {
|
||||||
SimpleAuth.authenticatePlayer(player, registerSuccess);
|
SimpleAuth.authenticatePlayer(player, registerSuccess);
|
||||||
|
|
|
@ -66,6 +66,9 @@ public class AuthConfig {
|
||||||
public String globalPassword = null;
|
public String globalPassword = null;
|
||||||
// Tries to rescue players if they are stuck inside a portal on logging in
|
// Tries to rescue players if they are stuck inside a portal on logging in
|
||||||
public boolean tryPortalRescue = true;
|
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 static class LangConfig {
|
||||||
public String enterPassword = "§6You need to enter your password!";
|
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 accountDeleted = "§aYour account was successfully deleted!";
|
||||||
public String configurationReloaded = "§aConfiguration file was reloaded successfully.";
|
public String configurationReloaded = "§aConfiguration file was reloaded successfully.";
|
||||||
public String successfulPortalRescue = "§aYou were rescued from nether portal 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 Logger LOGGER = LogManager.getLogger();
|
||||||
private static final Gson gson = new GsonBuilder()
|
private static final Gson gson = new GsonBuilder()
|
||||||
|
|
Loading…
Reference in New Issue