@@ -51,15 +51,35 @@ public class PasswordEncoderFactories {
51
51
* @return the {@link PasswordEncoder} to use
52
52
*/
53
53
public static PasswordEncoder createDelegatingPasswordEncoder () {
54
- String encodingId = "bcrypt" ;
54
+ return createDelegatingPasswordEncoder ("bcrypt" );
55
+ }
56
+
57
+ /**
58
+ * Creates a {@link DelegatingPasswordEncoder} with default mappings. Additional
59
+ * mappings may be added and the encoding will be updated to conform with best
60
+ * practices. However, due to the nature of {@link DelegatingPasswordEncoder} the
61
+ * updates should not impact users. The mappings current are:
62
+ *
63
+ * <ul>
64
+ * <li>bcrypt - {@link BCryptPasswordEncoder}</li>
65
+ * <li>noop - {@link NoOpPasswordEncoder}</li>
66
+ * <li>pbkdf2 - {@link Pbkdf2PasswordEncoder}</li>
67
+ * <li>scrypt - {@link SCryptPasswordEncoder}</li>
68
+ * <li>sha256 - {@link StandardPasswordEncoder}</li>
69
+ * </ul>
70
+ *
71
+ * @param idForEncode the id used to lookup which {@link PasswordEncoder} should be
72
+ * used for {@link PasswordEncoder#encode(CharSequence)}
73
+ * @return the {@link PasswordEncoder} to use
74
+ */
75
+ public static PasswordEncoder createDelegatingPasswordEncoder (String idForEncode ) {
55
76
Map <String ,PasswordEncoder > encoders = new HashMap <>();
56
- encoders .put (encodingId , new BCryptPasswordEncoder ());
77
+ encoders .put ("bcrypt" , new BCryptPasswordEncoder ());
57
78
encoders .put ("noop" , NoOpPasswordEncoder .getInstance ());
58
79
encoders .put ("pbkdf2" , new Pbkdf2PasswordEncoder ());
59
80
encoders .put ("scrypt" , new SCryptPasswordEncoder ());
60
81
encoders .put ("sha256" , new StandardPasswordEncoder ());
61
-
62
- return new DelegatingPasswordEncoder (encodingId , encoders );
82
+ return new DelegatingPasswordEncoder (idForEncode , encoders );
63
83
}
64
84
65
85
private PasswordEncoderFactories () {}
0 commit comments