// we start with a validation using patterns.
Matcher usernameMatcher = this.usernamePattern.matcher(username);
Matcher passwordMatcher = this.passwordPattern.matcher(password);
if (!usernameMatcher.matches() || !passwordMatcher.matches())
throw new InputValidationException("Username or password does not adhere to the acceptable pattern");
// now we proceed with a blacklist validation.
if (matchesBlackList(username) || matchesBlackList(password))
throw new InputValidationException("Username or password contains invalid tokens");
}