From ef6d5e826ee8f9ec8449603725902d3bb1bdbd30 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Sun, 10 Mar 2013 15:26:01 +0400 Subject: [PATCH] Fixed admin pswd not always parsed correctly on server --- Mage.Server/src/main/java/mage/server/Main.java | 2 ++ .../main/java/mage/server/util/SystemUtil.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Mage.Server/src/main/java/mage/server/Main.java b/Mage.Server/src/main/java/mage/server/Main.java index af6d9f4e2a..7338b27c9e 100644 --- a/Mage.Server/src/main/java/mage/server/Main.java +++ b/Mage.Server/src/main/java/mage/server/Main.java @@ -40,6 +40,7 @@ import mage.server.tournament.TournamentFactory; import mage.server.util.ConfigSettings; import mage.server.util.PluginClassLoader; import mage.server.util.ServerMessagesUtil; +import mage.server.util.SystemUtil; import mage.server.util.config.GamePlugin; import mage.server.util.config.Plugin; import mage.utils.MageVersion; @@ -106,6 +107,7 @@ public class Main { } else if (arg.startsWith(adminPasswordArg)) { adminPassword = arg.replace(adminPasswordArg, ""); + adminPassword = SystemUtil.sanitize(adminPassword); } } Connection connection = new Connection(); diff --git a/Mage.Server/src/main/java/mage/server/util/SystemUtil.java b/Mage.Server/src/main/java/mage/server/util/SystemUtil.java index 43dbcac95f..e2d6d55a66 100644 --- a/Mage.Server/src/main/java/mage/server/util/SystemUtil.java +++ b/Mage.Server/src/main/java/mage/server/util/SystemUtil.java @@ -148,4 +148,20 @@ public class SystemUtil { } return null; } + + public static String sanitize(String input) { + //Pattern pattern = Pattern.compile("[^0-9a-zA-Z]"); + //Matcher matcher = pattern.matcher(input); + //return matcher.replaceAll(""); + return input.replaceAll("[^a-zA-Z0-9]", ""); + } + + public static void main(String... args) { + System.out.println(sanitize("123")); + System.out.println(sanitize("AaAaD_123")); + System.out.println(sanitize("--sas-")); + System.out.println(sanitize("anPlsdf123_") + "|"); + System.out.println(sanitize("anPlsdf123 ") + "|"); + System.out.println(sanitize("anPlsdf123\r\n") + "|"); + } }