Add another java check about username lenght

This commit is contained in:
Sofia Baltzi 2017-10-30 13:00:20 +00:00
parent 11c2635512
commit 387f7ca4bf
1 changed files with 15 additions and 1 deletions

View File

@ -59,6 +59,7 @@ public class RegisterServlet extends HttpServlet {
} }
if (firstName != null && lastName != null && username != null && if (firstName != null && lastName != null && username != null &&
email.equals(confirmEmail) /*&& password.equals(confirmPassword)*/ ) { email.equals(confirmEmail) /*&& password.equals(confirmPassword)*/ ) {
try { try {
// if (ldapActions.usernameExists(username)) { // if (ldapActions.usernameExists(username)) {
@ -73,7 +74,7 @@ public class RegisterServlet extends HttpServlet {
// //
// } else { // } else {
if (!ldapActions.usernameExists(username) && !ldapActions.emailExists(email)) { if (username.matches("^[a-zA-Z0-9][a-zA-Z0-9_-]{4,150}") && !ldapActions.usernameExists(username) && !ldapActions.emailExists(email)) {
ldapActions.createUser(username, email, firstName, lastName, organization/*, password*/); ldapActions.createUser(username, email, firstName, lastName, organization/*, password*/);
logger.info("User successfully created"); logger.info("User successfully created");
@ -107,6 +108,19 @@ public class RegisterServlet extends HttpServlet {
// } // }
} else { } else {
if(!username.matches("^[a-zA-Z0-9][a-zA-Z0-9_-]{4,150}")){
if (username.length() < 5) {
request.getSession().setAttribute("username_message", "Minimum username length 5 characters.");
logger.info("Minimum username length 5 characters.");
}
if (username.length() > 150) {
request.getSession().setAttribute("username_message", "Maximum username lenght 150 characters.");
logger.info("Maximum username lenght 150 characters.");
}
}
if (ldapActions.usernameExists(username)) { if (ldapActions.usernameExists(username)) {
request.getSession().setAttribute("username_message", "Username already exists! Choose another one."); request.getSession().setAttribute("username_message", "Username already exists! Choose another one.");
logger.info("Username already exists"); logger.info("Username already exists");