BCryptPasswordEncoder is a Spring Security PasswordEncoder implementation that encodes passwords with the bcrypt strong hashing function. Use it when an application needs a password encoder rather than cleartext storage or weaker legacy hashing. section 4.1.3
Create the encoder with the constructor that matches the configuration needed:
- Use new BCryptPasswordEncoder() for the default configuration. section 4.1.3
- Use new BCryptPasswordEncoder(4) to provide a strength parameter. section 4.1.3
- Use new BCryptPasswordEncoder(4, s) when supplying both strength and a SecureRandom instance. section 4.1.3
Instantiate the encoder
PasswordEncoder p = new BCryptPasswordEncoder(); PasswordEncoder p = new BCryptPasswordEncoder(4); SecureRandom s = SecureRandom.getInstanceStrong(); PasswordEncoder p = new BCryptPasswordEncoder(4, s); section 4.1.3
BCryptPasswordEncoder can also serve as the bcrypt delegate inside DelegatingPasswordEncoder. A {bcrypt} prefix selects it for matching, while the delegating encoder can retain other implementations for differently prefixed hashes. section 4.1.4
