Class UserPasswordHelper

java.lang.Object
com.skava.helper.UserPasswordHelper

public final class UserPasswordHelper extends Object
This helper class contains methods that performs password validations and utilities associated to password.
Author:
Infosys Equinox
  • Method Details

    • isValidPassword

      public static boolean isValidPassword(String password, String validatorClass, String validatorConfig, Map<String,String> propMap, long collectionId, CollectionCommonServices collectionCommonServices)
      This method is used to validate whether the password is valid or not. Returns TRUE if password meets all the criteria defined in validator class and validator config else FALSE. Throws Exception if the validator class is not found or any error occurred while instantiating it and also if validator config is invalid.
      Parameters:
      password - Indicates the password which is used for validating the given password.
      validatorClass - Indicates the validator class for validating the password.
      validatorConfig - Indicates the validator config for validating the given password
      propMap - Indicates the collection properties map.
      collectionId - Indicates the collection id for which the limit property gets loaded.
      collectionCommonServices - Holds CollectionCommonServices which is used
      Returns:
      true, if it is a valid password else return false.
    • isPasswordBlacklisted

      public static boolean isPasswordBlacklisted(String password, long collectionId, CollectionCommonServices collectionCommonServices, boolean isValidPassword)
      This method is used to validate whether the password is blacklisted or not. Returns TRUE if password is not blacklisted else FALSE.
      Parameters:
      password - Indicates the password which is used for validating the given password.
      collectionId - Indicates the collection id for which the limit property gets loaded.
      collectionCommonServices - Holds CollectionCommonServices which is used for loading collection property from DB.
      isValidPassword - Indicates the password is valid or not.
      Returns:
      true, if it is a valid password else return false.
    • doPasswordHashing

      public static String doPasswordHashing(String password, String pwdHashAlgorithmClass)
      This method is used to hash the given password using hashing algorithm class and the BCrypt salt value. Throws Exception if the password hashing algorithm class is not found or error occurred while instantiating it.
      Parameters:
      password - Indicates the password which is used for validating the given password.
      pwdHashAlgorithmClass - Indicates the password hashing algorithm class for hashing the given password by using this class.
      Returns:
      the hashed password.
    • doPasswordHashing

      public static String doPasswordHashing(String password, PwdHashingStrategy pwdHashAlgorithm)
      This method is used to hash the given password using hashing algorithm class and the BCrypt salt value. Throws Exception if the password hashing algorithm class is not found or error occurred while instantiating it.
      Parameters:
      password - Indicates the password which is used for validating the given password.
      pwdHashAlgorithm - Holds PwdHashingStrategy for hashing the given password by using this algorithm.
      Returns:
      the hashed password.
    • getPwdHashAlgorithm

      public static PwdHashingStrategy getPwdHashAlgorithm(String pwdHashAlgorithmClass)
      This method is used to generate PwdHashingStrategy for the given pwdHashAlgorithmClass.
      Parameters:
      pwdHashAlgorithmClass - Indicates the pwdHashAlgorithmClass for creating PwdHashingStrategy object.
      Returns:
      the PwdHashingStrategy object.
    • updatePassword

      public static UsersResponse updatePassword(UserCommonServices userCommonServices, long userId, String password, String locale, Map<String,String> propMap, long collectionId, CollectionCommonServices collectionCommonServices)
      This method is used to update user password in DB, Password is validated and then saved in DB, current password is set as old password and new password is saved in DB if old password exists. Throws validation exception if validation fails.
      Parameters:
      userCommonServices - Holds UserCommonServices object for updating the password.
      userId - Indicates the identifier of an user.
      password - Indicates the password of an user which is used for updating password.
      propMap - Indicates the collection properties map
      locale - API Response and error messages will be responded in the locale mentioned in this parameter.
      collectionId - Indicates the collection id for which the limit property gets loaded.
      collectionCommonServices - Holds CollectionCommonServices which is used for loading collection property from DB.
      Returns:
      the UsersResponse object.
    • validatePasswordIntervalAndLimit

      public static UsersResponse validatePasswordIntervalAndLimit(UserCommonServices userCommonServices, long userId, String password, String locale, Map<String,String> propMap, long collectionId, CollectionCommonServices collectionCommonServices)
      Represents the response returned by the UserPasswordHelper.validatePasswordIntervalAndLimit method.
      Parameters:
      userCommonServices - The UserCommonServices object.
      userId - The user ID.
      password - The password.
      locale - The locale.
      propMap - The map of properties.
      collectionId - Indicates the collection id
      collectionCommonServices -
      Returns:
      The UsersResponse object.
    • getPropertiesEntity

      public static PropertiesEntity getPropertiesEntity(UsersEntity user)
      Retrieves the PropertiesEntity object associated with the given UsersEntity.
      Parameters:
      user - The UsersEntity object for which to retrieve the PropertiesEntity.
      Returns:
      The PropertiesEntity object associated with the given UsersEntity, or null if not found.
    • checkPassword

      public static boolean checkPassword(String passwordFromDB, String password)
      This method is used to compare the password present in DB with the password present in the request. Throws validation exception if the password hashing algorithm class is invalid or error while instantiating it.
      Parameters:
      passwordFromDB - Indicates the user password from DB used for checking the password.
      password - Indicates the user password which is used for checking the password.
      Returns:
      true, if both password matched successful.