Class ScryptPassword4jPasswordEncoder
java.lang.Object
org.springframework.security.crypto.password.AbstractValidatingPasswordEncoder
org.springframework.security.crypto.password4j.ScryptPassword4jPasswordEncoder
- All Implemented Interfaces:
PasswordEncoder
Implementation of
PasswordEncoder
that uses the Password4j library with SCrypt hashing algorithm.
SCrypt is a memory-hard password hashing algorithm designed to be resistant to hardware brute-force attacks. It includes built-in salt generation and is particularly effective against ASIC and GPU-based attacks. This implementation leverages Password4j's SCrypt 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 SCrypt settings (recommended)
PasswordEncoder encoder = new ScryptPassword4jPasswordEncoder();
// Using custom SCrypt configuration
PasswordEncoder customEncoder = new ScryptPassword4jPasswordEncoder(
ScryptFunction.getInstance(32768, 8, 1, 32));
- Since:
- 7.0
- See Also:
-
ScryptFunctionAlgorithmFinder.getScryptInstance()
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an SCrypt password encoder using the default SCrypt configuration from Password4j's AlgorithmFinder.ScryptPassword4jPasswordEncoder(com.password4j.ScryptFunction scryptFunction) Constructs an SCrypt password encoder with a custom SCrypt 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
-
ScryptPassword4jPasswordEncoder
public ScryptPassword4jPasswordEncoder()Constructs an SCrypt password encoder using the default SCrypt configuration from Password4j's AlgorithmFinder. -
ScryptPassword4jPasswordEncoder
public ScryptPassword4jPasswordEncoder(com.password4j.ScryptFunction scryptFunction) Constructs an SCrypt password encoder with a custom SCrypt function.- Parameters:
scryptFunction- the SCrypt function to use for encoding passwords, must not be null- Throws:
IllegalArgumentException- if scryptFunction is null
-
-
Method Details
-
encodeNonNullPassword
- Specified by:
encodeNonNullPasswordin classAbstractValidatingPasswordEncoder
-
matchesNonNull
- Specified by:
matchesNonNullin classAbstractValidatingPasswordEncoder
-
upgradeEncodingNonNull
- Overrides:
upgradeEncodingNonNullin classAbstractValidatingPasswordEncoder
-