Class BcryptPassword4jPasswordEncoder
java.lang.Object
org.springframework.security.crypto.password.AbstractValidatingPasswordEncoder
org.springframework.security.crypto.password4j.BcryptPassword4jPasswordEncoder
- All Implemented Interfaces:
PasswordEncoder
Implementation of
PasswordEncoder
that uses the Password4j library with BCrypt hashing algorithm.
BCrypt is a well-established password hashing algorithm that includes built-in salt generation and is resistant to rainbow table attacks. This implementation leverages Password4j's BCrypt support which properly includes the salt in the output hash.
This implementation is thread-safe and can be shared across multiple threads.
Usage Examples:
// Using default BCrypt settings (recommended)
PasswordEncoder encoder = new BcryptPassword4jPasswordEncoder();
// Using custom round count
PasswordEncoder customEncoder = new BcryptPassword4jPasswordEncoder(BcryptFunction.getInstance(12));
- Since:
- 7.0
- See Also:
-
BcryptFunctionAlgorithmFinder.getBcryptInstance()
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a BCrypt password encoder using the default BCrypt configuration from Password4j's AlgorithmFinder.BcryptPassword4jPasswordEncoder(com.password4j.BcryptFunction bcryptFunction) Constructs a BCrypt password encoder with a custom BCrypt function. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringencodeNonNullPassword(String rawPassword) protected booleanmatchesNonNull(String rawPassword, String encodedPassword) protected booleanupgradeEncodingNonNull(String encodedPassword) Methods inherited from class org.springframework.security.crypto.password.AbstractValidatingPasswordEncoder
encode, matches, upgradeEncoding
-
Constructor Details
-
BcryptPassword4jPasswordEncoder
public BcryptPassword4jPasswordEncoder()Constructs a BCrypt password encoder using the default BCrypt configuration from Password4j's AlgorithmFinder. -
BcryptPassword4jPasswordEncoder
public BcryptPassword4jPasswordEncoder(com.password4j.BcryptFunction bcryptFunction) Constructs a BCrypt password encoder with a custom BCrypt function.- Parameters:
bcryptFunction- the BCrypt function to use for encoding passwords, must not be null- Throws:
IllegalArgumentException- if bcryptFunction is null
-
-
Method Details
-
encodeNonNullPassword
- Specified by:
encodeNonNullPasswordin classAbstractValidatingPasswordEncoder
-
matchesNonNull
- Specified by:
matchesNonNullin classAbstractValidatingPasswordEncoder
-
upgradeEncodingNonNull
- Overrides:
upgradeEncodingNonNullin classAbstractValidatingPasswordEncoder
-