Class PasswordGenerator


  • public class PasswordGenerator
    extends Object
    Generates random passwords.

    This class allows to configure the password requirements for:

    • Number of upper case and lower case letters
    • Inclusion of numbers
    • Inclusion of special characters
    By default, it will include at least three lower case letters, three upper case, three numbers and three special characters, and a maximum of five from each set.

    It also allows to configure forbidden characters to accommodate the password requirements for the different clouds.

    Example usage:

     String password = new PasswordGenerator()
        .lower().count(3)  // Exactly three lower case characters
        .upper().count(2)  // Exactly 2 upper case characters 
        .numbers().min(5).exclude("012345".toCharArray()) // At least five numbers, from 6 to 9.
        .symbols().min(6).max(10) // Between 6 and 10 special characters
        .generate();
     
    • Constructor Detail

      • PasswordGenerator

        public PasswordGenerator()
    • Method Detail

      • lower

        public PasswordGenerator.Config lower()
        Returns the lower case configuration. Allows to configure the presence of lower case characters.
      • upper

        public PasswordGenerator.Config upper()
        Returns the upper case configuration. Allows to configure the presence of upper case characters.
      • numbers

        public PasswordGenerator.Config numbers()
        Returns the numbers configuration. Allows to configure the presence of numeric characters.
      • symbols

        public PasswordGenerator.Config symbols()
        Returns the special character configuration. Allows to configure the presence of special characters.
      • generate

        public String generate()
        Generates a random password using the configured spec.