public final class PasswordUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_ALGORITHM |
static int |
DEFAULT_ITERATIONS |
static int |
DEFAULT_SALT_SIZE |
| Modifier and Type | Method and Description |
|---|---|
static String |
buildPasswordHash(@NotNull String password)
Generates a hash of the specified password with the default values
for algorithm, salt-size and number of iterations.
|
static String |
buildPasswordHash(@NotNull String password,
@NotNull ConfigurationParameters config)
Same as
buildPasswordHash(String, String, int, int) but retrieving
the parameters for hash generation from the specified configuration. |
static String |
buildPasswordHash(@NotNull String password,
@Nullable 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 boolean |
isPlainTextPassword(@Nullable String password)
Returns
true if the specified string doesn't start with a
valid algorithm name in curly brackets. |
static boolean |
isSame(@Nullable String hashedPassword,
@NotNull char[] password)
Returns
true if hash of the specified password equals the
given hashed password. |
static boolean |
isSame(@Nullable String hashedPassword,
@NotNull String password)
Returns
true if hash of the specified password equals the
given hashed password. |
public static final String DEFAULT_ALGORITHM
public static final int DEFAULT_SALT_SIZE
public static final int DEFAULT_ITERATIONS
public static String buildPasswordHash(@NotNull @NotNull String password) throws NoSuchAlgorithmException, UnsupportedEncodingException
password - The password to be hashed.NoSuchAlgorithmException - If DEFAULT_ALGORITHM is not supported.UnsupportedEncodingException - If utf-8 is not supported.public static String buildPasswordHash(@NotNull @NotNull String password, @Nullable @Nullable String algorithm, int saltSize, int iterations) throws NoSuchAlgorithmException, UnsupportedEncodingException
password - The password to be hashed.algorithm - The desired hash algorithm. If the algorith is
null the DEFAULT_ALGORITHM will be used.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.NoSuchAlgorithmException - If the specified algorithm is not supported.UnsupportedEncodingException - If utf-8 is not supported.public static String buildPasswordHash(@NotNull @NotNull String password, @NotNull @NotNull ConfigurationParameters config) throws NoSuchAlgorithmException, UnsupportedEncodingException
buildPasswordHash(String, String, int, int) but retrieving
the parameters for hash generation from the specified configuration.password - The password to be hashed.config - The configuration defining the details of the hash generation.NoSuchAlgorithmException - If the specified algorithm is not supported.UnsupportedEncodingException - If utf-8 is not supported.public static boolean isPlainTextPassword(@Nullable
@Nullable String password)
true if the specified string doesn't start with a
valid algorithm name in curly brackets.password - The string to be tested.true if the specified string doesn't start with a
valid algorithm name in curly brackets.public static boolean isSame(@Nullable
@Nullable String hashedPassword,
@NotNull
@NotNull char[] password)
true if hash of the specified password equals the
given hashed password.hashedPassword - Password hash.password - The password to compare.password equals
the given hashedPassword string.public static boolean isSame(@Nullable
@Nullable String hashedPassword,
@NotNull
@NotNull String password)
true if hash of the specified password equals the
given hashed password.hashedPassword - Password hash.password - The password to compare.password equals
the given hashedPassword string.Copyright © 2012–2018 The Apache Software Foundation. All rights reserved.