Class PasswordHash

  • public class PasswordHash
    extends Object
    Handles hashing passwords to be stored in database supporting different HashingAlgorithms.
    • Method Detail

      • getUserWithPassword

        public static Optional<User> getUserWithPassword​(String userName,
                                                         String password)
        Checks if userName matches password, returning an Optional User in case it matches.

        Important Note: In case password matches with the current one for the user and it was hashed with a HashingAlgorithm with a version lower than current default, hash will be promoted to the default algorithm. In this case, user's password field will be updated and DAL current transaction will be flushed to DB.

        userName - user name to check
        password - user's password in plain text as provided by the user
        an Optional describing the User matching the provided userName and password pair; or an empty Optional if there is no User matching them
      • generateHash

        public static String generateHash​(String plainText)
        Generates a hash for the plainText using current default HashingAlgorithm
      • matches

        public static boolean matches​(String plainTextPassword,
                                      String hashedPassword)
        Checks whether a plain text password matches with a hashed password