diff --git a/core/src/main/java/com/muwire/core/Constants.java b/core/src/main/java/com/muwire/core/Constants.java index 4c1ce2ad..900040fd 100644 --- a/core/src/main/java/com/muwire/core/Constants.java +++ b/core/src/main/java/com/muwire/core/Constants.java @@ -5,6 +5,7 @@ import net.i2p.crypto.SigType; public class Constants { public static final byte PERSONA_VERSION = (byte)1; public static final String INVALID_NICKNAME_CHARS = "'\"();<>=@$%"; + public static final int MAX_NICKNAME_LENGTH = 30; public static final byte FILE_CERT_VERSION = (byte)2; public static final int CHAT_VERSION = 1; diff --git a/core/src/main/java/com/muwire/core/util/DataUtil.java b/core/src/main/java/com/muwire/core/util/DataUtil.java index bdd2a77b..baab322d 100644 --- a/core/src/main/java/com/muwire/core/util/DataUtil.java +++ b/core/src/main/java/com/muwire/core/util/DataUtil.java @@ -218,6 +218,8 @@ public class DataUtil { } public static boolean isValidName(String name) { + if (name.length() > Constants.MAX_NICKNAME_LENGTH) + return false; for (int i = 0; i < Constants.INVALID_NICKNAME_CHARS.length(); i++) if (name.indexOf(Constants.INVALID_NICKNAME_CHARS.charAt(i)) >= 0) return false; diff --git a/gui/griffon-app/lifecycle/Ready.groovy b/gui/griffon-app/lifecycle/Ready.groovy index 90130fa8..e31d2953 100644 --- a/gui/griffon-app/lifecycle/Ready.groovy +++ b/gui/griffon-app/lifecycle/Ready.groovy @@ -119,7 +119,8 @@ class Ready extends AbstractLifecycleHandler { continue } if (!DataUtil.isValidName(nickname)) { - JOptionPane.showMessageDialog(null, "Nickname cannot contain any of ${Constants.INVALID_NICKNAME_CHARS} choose another", + JOptionPane.showMessageDialog(null, + "Nickname cannot contain any of ${Constants.INVALID_NICKNAME_CHARS} and must be no longer than ${Constants.MAX_NICKNAME_LENGTH} characters. Choose another.", "Select another nickname", JOptionPane.WARNING_MESSAGE) continue } diff --git a/webui/src/main/java/com/muwire/webui/InitServlet.java b/webui/src/main/java/com/muwire/webui/InitServlet.java index adc10eb7..8853e50a 100644 --- a/webui/src/main/java/com/muwire/webui/InitServlet.java +++ b/webui/src/main/java/com/muwire/webui/InitServlet.java @@ -21,7 +21,8 @@ public class InitServlet extends HttpServlet { throw new Exception("Nickname cannot be blank"); if (!DataUtil.isValidName(nickname)) - throw new Exception("Nickname cannot contain any of " + Constants.INVALID_NICKNAME_CHARS); + throw new Exception("Nickname cannot contain any of " + Constants.INVALID_NICKNAME_CHARS + + " and must be no longer than " + Constants.MAX_NICKNAME_LENGTH + " characters."); String downloadLocation = req.getParameter("download_location"); if (downloadLocation == null)