Added login tries tracking.

This commit is contained in:
samo_lego 2020-03-18 19:18:40 +01:00
parent 2c16cb8318
commit 1f274c3034
3 changed files with 16 additions and 3 deletions

View File

@ -18,8 +18,9 @@ public class LoginCommand {
private static Text enterPassword = new LiteralText(SimpleAuth.config.lang.enterPassword); private static Text enterPassword = new LiteralText(SimpleAuth.config.lang.enterPassword);
private static Text wrongPassword = new LiteralText(SimpleAuth.config.lang.wrongPassword); private static Text wrongPassword = new LiteralText(SimpleAuth.config.lang.wrongPassword);
private static Text alreadyAuthenticated = new LiteralText(SimpleAuth.config.lang.alreadyAuthenticated); private static Text alreadyAuthenticated = new LiteralText(SimpleAuth.config.lang.alreadyAuthenticated);
//private static Text loginTriesExceeded = new LiteralText("§4Too many login tries."); private static Text loginTriesExceeded = new LiteralText(SimpleAuth.config.lang.loginTriesExceeded);
private static Text successfullyAuthenticated = new LiteralText(SimpleAuth.config.lang.successfullyAuthenticated); private static Text successfullyAuthenticated = new LiteralText(SimpleAuth.config.lang.successfullyAuthenticated);
private static int maxLoginTries = 3;
public static void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) { public static void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) {
// Registering the "/login" command // Registering the "/login" command
@ -41,6 +42,9 @@ public class LoginCommand {
player.sendMessage(alreadyAuthenticated); player.sendMessage(alreadyAuthenticated);
return 0; return 0;
} }
else if(SimpleAuth.deauthenticatedUsers.get(player) >= maxLoginTries && maxLoginTries != -1)
player.networkHandler.disconnect(loginTriesExceeded);
else if(SimpleAuth.config.main.enableGlobalPassword) { else if(SimpleAuth.config.main.enableGlobalPassword) {
if (AuthHelper.checkPass("globalPass", pass.toCharArray())) { if (AuthHelper.checkPass("globalPass", pass.toCharArray())) {
SimpleAuth.authenticatePlayer(player, successfullyAuthenticated); SimpleAuth.authenticatePlayer(player, successfullyAuthenticated);
@ -51,8 +55,12 @@ public class LoginCommand {
SimpleAuth.authenticatePlayer(player, successfullyAuthenticated); SimpleAuth.authenticatePlayer(player, successfullyAuthenticated);
return 1; return 1;
} }
player.networkHandler.disconnect(wrongPassword); else if(maxLoginTries == 1)
//player.sendMessage(wrongPassword); player.networkHandler.disconnect(wrongPassword);
player.sendMessage(wrongPassword);
SimpleAuth.deauthenticatedUsers.replace(player, SimpleAuth.deauthenticatedUsers.get(player) + 1);
return 0; return 0;
} }
} }

View File

@ -29,6 +29,7 @@ public class AuthEventHandler {
// Player joining the server // Player joining the server
public static void onPlayerJoin(ServerPlayerEntity player) { public static void onPlayerJoin(ServerPlayerEntity player) {
// Marking player as not authenticated, (re)setting login tries to zero
SimpleAuth.deauthenticatedUsers.put(player, 0); SimpleAuth.deauthenticatedUsers.put(player, 0);
/*CompoundTag loginTries = new CompoundTag(); /*CompoundTag loginTries = new CompoundTag();
loginTries.putInt("loginTries", 0); loginTries.putInt("loginTries", 0);

View File

@ -50,6 +50,9 @@ public class AuthConfig {
public boolean playerInvulnerable = true; public boolean playerInvulnerable = true;
// If player should be invisible to mobs before authentication // If player should be invisible to mobs before authentication
public boolean playerInvisible = true; public boolean playerInvisible = true;
// Maximum login tries before kicking the player
// Set to -1 to allow unlimited, not recommended however
public int maxLoginTries = 1;
// Time after which player will be kicked if not authenticated - in seconds // Time after which player will be kicked if not authenticated - in seconds
public int delay = 60; public int delay = 60;
// Disables registering and forces logging in with global password // Disables registering and forces logging in with global password
@ -67,6 +70,7 @@ public class AuthConfig {
public String matchPassword = "§6Passwords must match!"; public String matchPassword = "§6Passwords must match!";
public String passwordUpdated = "§4Your password was updated successfully!"; public String passwordUpdated = "§4Your password was updated successfully!";
public String loginRequired = "§cYou are not authenticated!\n§6Use /login to authenticate!"; public String loginRequired = "§cYou are not authenticated!\n§6Use /login to authenticate!";
public String loginTriesExceeded = "§4Too many login tries.";
public String globalPasswordSet = "§aGlobal password was successfully set!"; public String globalPasswordSet = "§aGlobal password was successfully set!";
public String cannotChangePassword = "§aYou cannot change password!"; public String cannotChangePassword = "§aYou cannot change password!";
public String cannotUnregister = "§aYou cannot unregister this account!"; public String cannotUnregister = "§aYou cannot unregister this account!";