make access password mandatory

This commit is contained in:
Sen 2025-05-26 20:29:08 +02:00
parent 5f49d6c036
commit 435e3f3e29
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
5 changed files with 35 additions and 7 deletions

View file

@ -252,6 +252,14 @@ public final class Server implements IThreadListener {
Server.this.bind(Config.port);
}
}, "port");
Config.setCallback(new Runnable() {
public void run() {
if(Config.password.length() < 8 || Config.password.length() > IPlayer.MAX_PASS_LENGTH) {
Log.IO.error("Passwort muss aus 8-" + IPlayer.MAX_PASS_LENGTH + " Zeichen bestehen");
Config.set("password", "", false);
}
}
}, "password");
this.keyPair = EncryptUtil.generateKeyPair();
}
@ -440,7 +448,7 @@ public final class Server implements IThreadListener {
}
}
Config.set(args[0], value, true);
exec.logConsole(TextColor.YELLOW + "%s" + TextColor.GRAY + " -> " + ((cv.type == ValueType.BOOLEAN ? (cv.getValue().equals("true") ? TextColor.GREEN : TextColor.RED) : (cv.type == ValueType.STRING ? TextColor.NEON : TextColor.BLUE))) + "%s", args[0], cv.type == ValueType.STRING ? ("'" + cv.getValue() + "'") : cv.getValue());
exec.logConsole(TextColor.YELLOW + "%s" + TextColor.GRAY + " -> " + (cv.noDef && cv.def.equals(cv.getValue()) ? TextColor.DGRAY + "[ - ]" : ((cv.type == ValueType.BOOLEAN ? (cv.getValue().equals("true") ? TextColor.GREEN : TextColor.RED) : (cv.type == ValueType.STRING ? TextColor.NEON : TextColor.BLUE))) + "%s"), args[0], cv.type == ValueType.STRING ? ("'" + cv.getValue() + "'") : cv.getValue());
}
return true;
}
@ -504,6 +512,8 @@ public final class Server implements IThreadListener {
this.bind(Config.port);
else
Log.SYSTEM.warn("Kein Port definiert, verwende 'port <1024-32767>' um einen Hosting-Port festzulegen");
if(Config.password.length() < 8)
Log.SYSTEM.warn("Kein Passwort definiert, verwende 'password <8-" + IPlayer.MAX_PASS_LENGTH + " Zeichen>' um ein Zugangspasswort festzulegen");
Thread con = new Thread(new Runnable() {
private final BufferedReader reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(System.in)));

View file

@ -133,7 +133,11 @@ public class LoginHandler extends NetHandler implements ILoginHandler
throw new IllegalStateException("Ungültiger Nutzername!");
// if(!this.checkConnect(packetIn.getAccess()))
// return;
if(!Config.password.isEmpty() && !Config.password.equals(packetIn.getAccess())) {
if(Config.password.length() < 8) {
this.closeConnection("Es ist kein Zugangspasswort für diesen Server konfiguriert");
return;
}
if(!Config.password.equals(packetIn.getAccess())) {
this.closeConnection("Falsches Zugangspasswort");
return;
}