size limit on nicknames

This commit is contained in:
Zlatin Balevsky
2020-05-10 09:51:56 +01:00
parent 3b825263a7
commit 992daa1e45
4 changed files with 7 additions and 2 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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
}

View File

@ -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)