public class PasswordUtility 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(String password)
Generates a hash of the specified password with the default values
for algorithm, salt-size and number of iterations.
|
static String |
buildPasswordHash(String password,
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 String |
extractAlgorithm(String hashedPwd)
Extract the algorithm from the given crypted password string.
|
static boolean |
isPlainTextPassword(String password)
Returns
true if the specified string doesn't start with a
valid algorithm name in curly brackets. |
static boolean |
isSame(String hashedPassword,
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(String password) throws NoSuchAlgorithmException
password
- The password to be hashed.NoSuchAlgorithmException
- If DEFAULT_ALGORITHM
is not supported.public static String buildPasswordHash(String password, String algorithm, int saltSize, int iterations) throws NoSuchAlgorithmException
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.NoSuchAlgorithmException
- If the specified algorithm is not supported.public static boolean isPlainTextPassword(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(String hashedPassword, 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.public static String extractAlgorithm(String hashedPwd)
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.hashedPwd
- The password hash.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.Copyright © 2004–2021 The Apache Software Foundation. All rights reserved.