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
Modifier and TypeFieldDescriptionstatic final int
The default cost:10
.static final int
The default salt length in kikibytes:16
. -
Constructor Summary
ConstructorDescriptionEncoder()
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.boolean
int
getCost()
Returns the cost.int
Returns the salt length in kikibytes.Returns the secure random.int
hashCode()
boolean
Matches 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, wait
Methods 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.Encoder
Recovers a password from its encoded representation generated with this encoder.
- Specified by:
recover
in 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.Encoder
Encodes the specified raw password.
- Specified by:
encode
in 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.Encoder
Matches the specified raw password with the specified encoded representation.
- Specified by:
matches
in 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
-