Class BcryptPassword4jPasswordEncoder

java.lang.Object
org.springframework.security.crypto.password.AbstractValidatingPasswordEncoder
org.springframework.security.crypto.password4j.BcryptPassword4jPasswordEncoder
All Implemented Interfaces:
PasswordEncoder

public class BcryptPassword4jPasswordEncoder extends AbstractValidatingPasswordEncoder
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:
  • BcryptFunction
  • AlgorithmFinder.getBcryptInstance()
  • 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