/** {@inheritDoc} */
  @Override()
  public boolean passwordIsAcceptable(
      ByteString newPassword,
      Set<ByteString> currentPasswords,
      Operation operation,
      Entry userEntry,
      MessageBuilder invalidReason) {
    // Get a handle to the current configuration and see if we need to count
    // the number of repeated characters in the password.
    RepeatedCharactersPasswordValidatorCfg config = currentConfig;
    int maxRepeats = config.getMaxConsecutiveLength();
    if (maxRepeats <= 0) {
      // We don't need to check anything, so the password will be acceptable.
      return true;
    }

    // Get the password as a string.  If we should use case-insensitive
    // validation, then convert it to use all lowercase characters.
    String passwordString = newPassword.toString();
    if (!config.isCaseSensitiveValidation()) {
      passwordString = passwordString.toLowerCase();
    }

    // Create variables to keep track of the last character we've seen and how
    // many times we have seen it.
    char lastCharacter = '\u0000';
    int consecutiveCount = 0;

    // Iterate through the characters in the password.  If the consecutive
    // count ever gets too high, then fail.
    for (int i = 0; i < passwordString.length(); i++) {
      char currentCharacter = passwordString.charAt(i);
      if (currentCharacter == lastCharacter) {
        consecutiveCount++;
        if (consecutiveCount > maxRepeats) {
          Message message = ERR_REPEATEDCHARS_VALIDATOR_TOO_MANY_CONSECUTIVE.get(maxRepeats);
          invalidReason.append(message);
          return false;
        }
      } else {
        lastCharacter = currentCharacter;
        consecutiveCount = 1;
      }
    }

    return true;
  }
 /** {@inheritDoc} */
 @Override()
 public void finalizePasswordValidator() {
   currentConfig.removeRepeatedCharactersChangeListener(this);
 }
 /** {@inheritDoc} */
 @Override()
 public void initializePasswordValidator(RepeatedCharactersPasswordValidatorCfg configuration) {
   configuration.addRepeatedCharactersChangeListener(this);
   currentConfig = configuration;
 }