Class PasswordUtils


  • public class PasswordUtils
    extends java.lang.Object
    Utils class from JCR core
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String buildPasswordHash​(java.lang.String password)
      Generates a hash of the specified password with the default values for algorithm, salt-size and number of iterations.
      static java.lang.String buildPasswordHash​(java.lang.String password, java.lang.String algorithm, int saltSize, int iterations)
      Generates a hash of the specified password using the specified algorithm, salt size and number of iterations into account.
      static java.lang.String extractAlgorithm​(java.lang.String hashedPwd)
      Extract the algorithm from the given crypted password string.
      static boolean isPlainTextPassword​(java.lang.String password)
      Returns true if the specified string doesn't start with a valid algorithm name in curly brackets.
      static boolean isSame​(java.lang.String hashedPassword, java.lang.String password)
      Returns true if hash of the specified password equals the given hashed password.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • buildPasswordHash

        public static java.lang.String buildPasswordHash​(java.lang.String password)
                                                  throws java.security.NoSuchAlgorithmException,
                                                         java.io.UnsupportedEncodingException
        Generates a hash of the specified password with the default values for algorithm, salt-size and number of iterations.
        Parameters:
        password - The password to be hashed.
        Returns:
        The password hash.
        Throws:
        java.security.NoSuchAlgorithmException - If DEFAULT_ALGORITHM is not supported.
        java.io.UnsupportedEncodingException - If utf-8 is not supported.
      • buildPasswordHash

        public static java.lang.String buildPasswordHash​(java.lang.String password,
                                                         java.lang.String algorithm,
                                                         int saltSize,
                                                         int iterations)
                                                  throws java.security.NoSuchAlgorithmException,
                                                         java.io.UnsupportedEncodingException
        Generates a hash of the specified password using the specified algorithm, salt size and number of iterations into account.
        Parameters:
        password - The password to be hashed.
        algorithm - The desired hash algorithm.
        saltSize - The desired salt size. If the specified integer is lower that DEFAULT_SALT_SIZE the default is used.
        iterations - The desired number of iterations. If the specified integer is lower than 1 the default value is used.
        Returns:
        The password hash.
        Throws:
        java.security.NoSuchAlgorithmException - If the specified algorithm is not supported.
        java.io.UnsupportedEncodingException - If utf-8 is not supported.
      • isPlainTextPassword

        public static boolean isPlainTextPassword​(java.lang.String password)
        Returns true if the specified string doesn't start with a valid algorithm name in curly brackets.
        Parameters:
        password - The string to be tested.
        Returns:
        true if the specified string doesn't start with a valid algorithm name in curly brackets.
      • isSame

        public static boolean isSame​(java.lang.String hashedPassword,
                                     java.lang.String password)
        Returns true if hash of the specified password equals the given hashed password.
        Parameters:
        hashedPassword - Password hash.
        password - The password to compare.
        Returns:
        If the hash of the specified password equals the given hashedPassword string.
      • extractAlgorithm

        public static java.lang.String extractAlgorithm​(java.lang.String hashedPwd)
        Extract the algorithm from the given crypted password string. Returns the algorithm or null if the given string doesn't have a leading algorithm such as created by buildPasswordHash or if the extracted string doesn't represent an available algorithm.
        Parameters:
        hashedPwd - The password hash.
        Returns:
        The algorithm or null if the given string doesn't have a leading algorithm such as created by buildPasswordHash or if the extracted string isn't a supported algorithm.