Class PasswordUtil
- java.lang.Object
-
- org.apache.jackrabbit.oak.spi.security.user.util.PasswordUtil
-
public final class PasswordUtil extends java.lang.ObjectUtility to generate and compare password hashes.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_ALGORITHMstatic intDEFAULT_ITERATIONSstatic intDEFAULT_SALT_SIZE
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringbuildPasswordHash(@NotNull 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.StringbuildPasswordHash(@NotNull java.lang.String password, @NotNull ConfigurationParameters config)Same asbuildPasswordHash(String, String, int, int)but retrieving the parameters for hash generation from the specified configuration.static java.lang.StringbuildPasswordHash(@NotNull java.lang.String password, @Nullable 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 booleanisPlainTextPassword(@Nullable java.lang.String password)Returnstrueif the specified string doesn't start with a valid algorithm name in curly brackets.static booleanisSame(@Nullable java.lang.String hashedPassword, @org.jetbrains.annotations.NotNull char[] password)Returnstrueif hash of the specifiedpasswordequals the given hashed password.static booleanisSame(@Nullable java.lang.String hashedPassword, @NotNull java.lang.String password)Returnstrueif hash of the specifiedpasswordequals the given hashed password.
-
-
-
Field Detail
-
DEFAULT_ALGORITHM
public static final java.lang.String DEFAULT_ALGORITHM
- See Also:
- Constant Field Values
-
DEFAULT_SALT_SIZE
public static final int DEFAULT_SALT_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_ITERATIONS
public static final int DEFAULT_ITERATIONS
- See Also:
- Constant Field Values
-
-
Method Detail
-
buildPasswordHash
public static java.lang.String buildPasswordHash(@NotNull @NotNull java.lang.String password) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingExceptionGenerates 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- IfDEFAULT_ALGORITHMis not supported.java.io.UnsupportedEncodingException- If utf-8 is not supported.
-
buildPasswordHash
public static java.lang.String buildPasswordHash(@NotNull @NotNull java.lang.String password, @Nullable @Nullable java.lang.String algorithm, int saltSize, int iterations) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingExceptionGenerates 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. If the algorith isnulltheDEFAULT_ALGORITHMwill be used.saltSize- The desired salt size. If the specified integer is lower thatDEFAULT_SALT_SIZEthe default is used.iterations- The desired number of iterations. If the specified integer is lower than 1 thedefaultvalue 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.
-
buildPasswordHash
public static java.lang.String buildPasswordHash(@NotNull @NotNull java.lang.String password, @NotNull @NotNull ConfigurationParameters config) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingExceptionSame asbuildPasswordHash(String, String, int, int)but retrieving the parameters for hash generation from the specified configuration.- Parameters:
password- The password to be hashed.config- The configuration defining the details of the hash generation.- 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(@Nullable @Nullable java.lang.String password)Returnstrueif the specified string doesn't start with a valid algorithm name in curly brackets.- Parameters:
password- The string to be tested.- Returns:
trueif the specified string doesn't start with a valid algorithm name in curly brackets.
-
isSame
public static boolean isSame(@Nullable @Nullable java.lang.String hashedPassword, @NotNull @org.jetbrains.annotations.NotNull char[] password)Returnstrueif hash of the specifiedpasswordequals the given hashed password.- Parameters:
hashedPassword- Password hash.password- The password to compare.- Returns:
- If the hash created from the specified
passwordequals the givenhashedPasswordstring.
-
isSame
public static boolean isSame(@Nullable @Nullable java.lang.String hashedPassword, @NotNull @NotNull java.lang.String password)Returnstrueif hash of the specifiedpasswordequals the given hashed password.- Parameters:
hashedPassword- Password hash.password- The password to compare.- Returns:
- If the hash created from the specified
passwordequals the givenhashedPasswordstring.
-
-