Class SecurePasswordGenerator

java.lang.Object
fr.becpg.repo.authentication.SecurePasswordGenerator

public class SecurePasswordGenerator extends Object
Utility class that generates a random password using a cryptographically strong random source (SecureRandom).

The generated password has the following characteristics:

  • Length: 15 characters.
  • Contains at least one uppercase letter (A-Z but I O).
  • Contains at least one lowercase letter (a-z but l).
  • Contains at least one digit (2-9).
  • Contains at least one special character from: @%*-_=+! .

The password is sent by mail and typed back by the user, so the alphabet excludes characters that alter or blur it: & and # start HTML character references a mail client decodes, I l 1 O 0 look alike, ^ is a dead key on AZERTY keyboards and punctuation such as . ( ) [ ] stops a double-click selection.

Author:
matthieu
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final String
    Constant ALL="UPPER + LOWER + DIGIT + SPECIAL"
    private static final String
    Constant DIGIT="23456789"
    private static final String
    Constant LOWER="abcdefghijkmnopqrstuvwxyz"
    private static final SecureRandom
    Constant RANDOM
    private static final int
    Number of characters drawn from ALL once each character class holds one: 15 characters in all, one more than the policy minimum, to make up for the smaller alphabet (about 90 bits of entropy).
    (package private) static final String
    Constant SPECIAL="@%*-_=+!"
    private static final String
    Constant UPPER="ABCDEFGHJKLMNPQRSTUVWXYZ"
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Constructor for SecurePasswordGenerator.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    generatePassword.
    private static char
    randomChar.
    private static String
    shuffleString.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • RANDOM

      private static final SecureRandom RANDOM
      Constant RANDOM
    • UPPER

      private static final String UPPER
      Constant UPPER="ABCDEFGHJKLMNPQRSTUVWXYZ"
      See Also:
    • LOWER

      private static final String LOWER
      Constant LOWER="abcdefghijkmnopqrstuvwxyz"
      See Also:
    • DIGIT

      private static final String DIGIT
      Constant DIGIT="23456789"
      See Also:
    • SPECIAL

      static final String SPECIAL
      Constant SPECIAL="@%*-_=+!"
      See Also:
    • ALL

      static final String ALL
      Constant ALL="UPPER + LOWER + DIGIT + SPECIAL"
      See Also:
    • RANDOM_CHAR_COUNT

      private static final int RANDOM_CHAR_COUNT
      Number of characters drawn from ALL once each character class holds one: 15 characters in all, one more than the policy minimum, to make up for the smaller alphabet (about 90 bits of entropy).
      See Also:
  • Constructor Details

    • SecurePasswordGenerator

      private SecurePasswordGenerator()

      Constructor for SecurePasswordGenerator.

  • Method Details

    • generatePassword

      public static String generatePassword()

      generatePassword.

      Returns:
      a String object
    • randomChar

      private static char randomChar(String chars)

      randomChar.

      Parameters:
      chars - a String object
      Returns:
      a char
    • shuffleString

      private static String shuffleString(String input)

      shuffleString.

      Parameters:
      input - a String object
      Returns:
      a String object