Package org.passay

Class PasswordGenerator


  • public class PasswordGenerator
    extends Object
    Creates passwords that meet password character rule criteria.
    Author:
    Sean C. Sullivan, Middleware Services
    • Constructor Detail

      • PasswordGenerator

        public PasswordGenerator()
        Default constructor. Instantiates a secure random for password generation.
      • PasswordGenerator

        public PasswordGenerator​(Random r)
        Creates a new password generator with the supplied random.
        Parameters:
        r - random
    • Method Detail

      • generatePassword

        public String generatePassword​(int length,
                                       CharacterRule... rules)
        Parameters:
        length - of password to generate
        rules - to generate compliant password from
        Returns:
        generated password
      • generatePassword

        public String generatePassword​(int length,
                                       List<CharacterRule> rules)
        Generates a password of the supplied length which meets the requirements of the supplied character rules. For length to be evaluated it must be greater than the number of characters defined in the character rule.
        Parameters:
        length - of password to generate
        rules - to generate compliant password from
        Returns:
        generated password
      • fillRandomCharacters

        protected void fillRandomCharacters​(CharSequence source,
                                            int count,
                                            Appendable target)
        Fills the supplied target with count random characters from source.
        Parameters:
        source - of random characters.
        count - number of random characters.
        target - character sequence that will hold characters.
      • randomize

        protected void randomize​(CharBuffer buffer)
        Randomizes the contents of the given buffer.
        Parameters:
        buffer - character buffer whose contents will be randomized.