public String createSecurePassword(Integer length, Integer minLowercaseLetters, Integer minUppercaseLetters, Integer minDigits, Integer minPunctuation, Integer minWhitespace) {
    if ((length == null) || (length < 1)) {
      length = SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_LENGTH;
    }

    if (minLowercaseLetters == null) {
      minLowercaseLetters = SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_LOWERCASE_LETTERS;
    }

    if (minUppercaseLetters == null) {
      minUppercaseLetters = SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_UPPERCASE_LETTERS;
    }

    if (minDigits == null) {
      minDigits = SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_DIGITS;
    }

    if (minPunctuation == null) {
      minPunctuation = SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_PUNCTUATION;
    }

    if (minWhitespace == null) {
      minWhitespace = SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_WHITESPACE;
    }

    // Gather the set of characters that meet the specified requirements
    List<Character> characters = new ArrayList<>(length);

    for (int i = 0; i < minLowercaseLetters; i++) {
      characters.add(SecurePasswordHelper.SECURE_PASSWORD_CHARACTER_CLASS_LOWERCASE_LETTERS[secureRandom.nextInt(SecurePasswordHelper.SECURE_PASSWORD_CHARACTER_CLASS_LOWERCASE_LETTERS.length)]);
    }

    for (int i = 0; i < minUppercaseLetters; i++) {
      characters.add(SecurePasswordHelper.SECURE_PASSWORD_CHARACTER_CLASS_UPPERCASE_LETTERS[secureRandom.nextInt(SecurePasswordHelper.SECURE_PASSWORD_CHARACTER_CLASS_UPPERCASE_LETTERS.length)]);
    }

    for (int i = 0; i < minDigits; i++) {
      characters.add(SecurePasswordHelper.SECURE_PASSWORD_CHARACTER_CLASS_DIGITS[secureRandom.nextInt(SecurePasswordHelper.SECURE_PASSWORD_CHARACTER_CLASS_DIGITS.length)]);
    }

    for (int i = 0; i < minPunctuation; i++) {
      characters.add(SecurePasswordHelper.SECURE_PASSWORD_CHARACTER_CLASS_PUNCTUATION[secureRandom.nextInt(SecurePasswordHelper.SECURE_PASSWORD_CHARACTER_CLASS_PUNCTUATION.length)]);
    }

    for (int i = 0; i < minWhitespace; i++) {
      characters.add(SecurePasswordHelper.SECURE_PASSWORD_CHARACTER_CLASS_WHITESPACE[secureRandom.nextInt(SecurePasswordHelper.SECURE_PASSWORD_CHARACTER_CLASS_WHITESPACE.length)]);
    }

    // If we need to gather more characters, select randomly from the set of character classes
    if (characters.size() < length) {
      int difference = length - characters.size();
      for (int i = 0; i < difference; i++) {
        char[] characterClass = SecurePasswordHelper.SECURE_PASSWORD_CHARACTER_CLASSES[secureRandom.nextInt(SecurePasswordHelper.SECURE_PASSWORD_CHARACTER_CLASSES.length - 1)];
        characters.add(characterClass[secureRandom.nextInt(characterClass.length)]);
      }
    }

    // Generate the password string by randomly selecting from the list of available characters
    StringBuilder passwordBuilder = new StringBuilder(characters.size());

    while (!characters.isEmpty()) {
      passwordBuilder.append(characters.remove(secureRandom.nextInt(characters.size())));
    }

    return passwordBuilder.toString();
  }
Create a secure (random) password using a secure random number generator, a set of (reasonable)
characters, and meeting the specified rules.
<p/>
If any rule is <code>null</code>, it's default value will be used:
<ul>
<li>length: 18</li>
<li>minimum lowercase letters (a-z): 1</li>
<li>minimum uppercase letters (A-Z): 1</li>
<li>minimum digits (0-9): 1</li>
<li>minimum punctuation (?.!$%^*()-_+=~): 1</li>
<li>minimum whitespace ( ): 0</li>
</ul>

@param length              the required length of the generated password
@param minLowercaseLetters the required minimum number of lowercase letters
@param minUppercaseLetters the required minimum number of uppercase letters
@param minDigits           the required minimum number of digits
@param minPunctuation      the required minimum number of punctuation characters
@param minWhitespace       the required minimum number of space characters
@return a String containing the new password
ambari-server/src/main/java/org/apache/ambari/server/security/SecurePasswordHelper.java