I am facing trouble in doing password validation. I am taking the min and max value for the range of password from the java class called applicationconstants and calling that in the servlets. I am using the validation function in another java class and calling that in servlet. Please help me in solving this problem.
servlet code
int minLength = ApplicationConstants.PASSWORD_MIN_LENGTH;
int maxLength = ApplicationConstants.PASSWORD_MAX_LENGTH;
if (user.getUserPassword().length() > 0 || user.getUserPassword() !=null) {
if (Validation.validateStringLengthRange(user.getUserPassword(), minLength, maxLength)) {
System.out.println("servlet");
isvalidate = false;
hashMap.put("password", props.getText("error.password.compare.outofrange"));
session.setAttribute("errorMessage", hashMap);
}
}
Validation.java
public static boolean validateStringLengthRange(String name, int min, int max) {
boolean isValid = true;
int len = name.length();
if (len > 0) {
if (len < min || len > max) {
System.out.println("validation.java");
isValid = false;
}
}
return isValid;
}
ApplicationConstants.java
public static final int PASSWORD_MIN_LENGTH = 6;
public static final int PASSWORD_MAX_LENGTH = 18;