diff --git a/Mage.Server/config/config.xml b/Mage.Server/config/config.xml index fb03316cb0..0e21072f77 100644 --- a/Mage.Server/config/config.xml +++ b/Mage.Server/config/config.xml @@ -1,7 +1,7 @@ - + diff --git a/Mage.Server/release/config/config.xml b/Mage.Server/release/config/config.xml index c1dd6408fb..22ab1fd523 100644 --- a/Mage.Server/release/config/config.xml +++ b/Mage.Server/release/config/config.xml @@ -1,7 +1,7 @@ - + diff --git a/Mage.Server/src/main/java/mage/server/Session.java b/Mage.Server/src/main/java/mage/server/Session.java index 3e0dad491f..1d3c22d3cf 100644 --- a/Mage.Server/src/main/java/mage/server/Session.java +++ b/Mage.Server/src/main/java/mage/server/Session.java @@ -41,6 +41,9 @@ import org.jboss.remoting.callback.InvokerCallbackHandler; import java.util.Date; import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import mage.server.util.ConfigSettings; /** * @@ -69,6 +72,17 @@ public class Session { this.isAdmin = false; if (userName.equals("Admin")) throw new MageException("User name already in use"); + if (userName.length() > ConfigSettings.getInstance().getMaxUserNameLength()) { + throw new MageException(new StringBuilder("User name may not be longer than ").append(ConfigSettings.getInstance().getMaxUserNameLength()).append(" characters").toString()); + } + if (userName.length() < ConfigSettings.getInstance().getMinUserNameLength()) { + throw new MageException(new StringBuilder("User name may not be shorter than ").append(ConfigSettings.getInstance().getMinUserNameLength()).append(" characters").toString()); + } + Pattern p = Pattern.compile(ConfigSettings.getInstance().getUserNamePattern(), Pattern.CASE_INSENSITIVE); + Matcher m = p.matcher(userName); + if (m.find()) { + throw new MageException("User name includes not allowed characters: use a-z, A-Z and 0-9"); + } User user = UserManager.getInstance().createUser(userName, host); if (user == null) { // user already exists user = UserManager.getInstance().findUser(userName); diff --git a/Mage.Server/src/main/java/mage/server/util/Config.xsd b/Mage.Server/src/main/java/mage/server/util/Config.xsd index ac06d7978d..5d855fec82 100644 --- a/Mage.Server/src/main/java/mage/server/util/Config.xsd +++ b/Mage.Server/src/main/java/mage/server/util/Config.xsd @@ -21,6 +21,9 @@ + + + diff --git a/Mage.Server/src/main/java/mage/server/util/ConfigSettings.java b/Mage.Server/src/main/java/mage/server/util/ConfigSettings.java index 8cf5d2e18a..6255b3b18c 100644 --- a/Mage.Server/src/main/java/mage/server/util/ConfigSettings.java +++ b/Mage.Server/src/main/java/mage/server/util/ConfigSettings.java @@ -83,6 +83,18 @@ public class ConfigSettings { return config.getServer().getMaxSecondsIdle().intValue(); } + public int getMinUserNameLength() { + return config.getServer().getMinUserNameLength().intValue(); + } + + public int getMaxUserNameLength() { + return config.getServer().getMaxUserNameLength().intValue(); + } + + public String getUserNamePattern() { + return config.getServer().getUserNamePattern(); + } + public List getPlayerTypes() { return config.getPlayerTypes().getPlayerType(); } diff --git a/Mage.Server/src/main/xml-resources/jaxb/Config/Config.xsd b/Mage.Server/src/main/xml-resources/jaxb/Config/Config.xsd index e83f1f6a45..ddcce51ad0 100644 --- a/Mage.Server/src/main/xml-resources/jaxb/Config/Config.xsd +++ b/Mage.Server/src/main/xml-resources/jaxb/Config/Config.xsd @@ -21,6 +21,9 @@ + + +