Module io.inverno.mod.security
Class BCryptPassword.Encoder
java.lang.Object
io.inverno.mod.security.authentication.password.BCryptPassword.Encoder
- All Implemented Interfaces:
Password.Encoder<BCryptPassword,BCryptPassword.Encoder>
- Enclosing class:
BCryptPassword
public static class BCryptPassword.Encoder
extends Object
implements Password.Encoder<BCryptPassword,BCryptPassword.Encoder>
A Bcrypt password encoder implementation.
- Since:
- 1.5
- Author:
- Jeremy Kuhn
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default cost:10.static final intThe default salt length in kikibytes:16. -
Constructor Summary
ConstructorsConstructorDescriptionEncoder()Creates a default Bcrypt password encoder.Encoder(int cost, int saltLength) Creates a Bcrypt password encoder with the specified cost and salt length.Encoder(int cost, int saltLength, SecureRandom secureRandom) Creates a Bcrypt password encoder with the specified cost, salt length and secure random. -
Method Summary
Modifier and TypeMethodDescriptionEncodes the specified raw password.booleanintgetCost()Returns the cost.intReturns the salt length in kikibytes.Returns the secure random.inthashCode()booleanMatches the specified raw password with the specified encoded representation.Recovers a password from its encoded representation generated with this encoder.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.inverno.mod.security.authentication.password.Password.Encoder
matches
-
Field Details
-
DEFAULT_COST
public static final int DEFAULT_COSTThe default cost:10.- See Also:
-
SALT_LENGTH
public static final int SALT_LENGTHThe default salt length in kikibytes:16.- See Also:
-
-
Constructor Details
-
Encoder
public Encoder()Creates a default Bcrypt password encoder.
-
Encoder
Creates a Bcrypt password encoder with the specified cost and salt length.
- Parameters:
cost- the costsaltLength- the salt length in kikibytes- Throws:
IllegalArgumentException- if specified parameters are incorrect
-
Encoder
Creates a Bcrypt password encoder with the specified cost, salt length and secure random.
- Parameters:
cost- the costsaltLength- the salt length in kikibytessecureRandom- the secure random- Throws:
IllegalArgumentException- if specified parameters are incorrect
-
-
Method Details
-
getCost
public int getCost()Returns the cost.
- Returns:
- the cost
-
getSaltLength
public int getSaltLength()Returns the salt length in kikibytes.
- Returns:
- the salt length
-
getSecureRandom
Returns the secure random.
- Returns:
- the secure random
-
recover
Description copied from interface:Password.EncoderRecovers a password from its encoded representation generated with this encoder.
- Specified by:
recoverin interfacePassword.Encoder<BCryptPassword,BCryptPassword.Encoder> - Parameters:
encoded- an encoded password representation- Returns:
- a password
- Throws:
PasswordException- if there was an error recovering the password or if the specified encoded representation was not generated with this encoder
-
encode
Description copied from interface:Password.EncoderEncodes the specified raw password.
- Specified by:
encodein interfacePassword.Encoder<BCryptPassword,BCryptPassword.Encoder> - Parameters:
raw- a raw password- Returns:
- an encoded password
- Throws:
PasswordException- if there was an error encoding the password
-
matches
Description copied from interface:Password.EncoderMatches the specified raw password with the specified encoded representation.
- Specified by:
matchesin interfacePassword.Encoder<BCryptPassword,BCryptPassword.Encoder> - Parameters:
raw- a raw passwordencoded- an encoded password- Returns:
- true if passwords match, false otherwise
- Throws:
PasswordException- if there was an error matching passwords
-
hashCode
public int hashCode() -
equals
-