PasswordEncoder 配置

PasswordEncoder 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
@Bean
public PasswordEncoder passwordEncoder() {
String bcrypt = "bcrypt";
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
Map<String, PasswordEncoder> encoders = new HashMap<>(8);
encoders.put(bcrypt, new BCryptPasswordEncoder());
encoders.put("pbkdf2", new Pbkdf2PasswordEncoder());
encoders.put("scrypt", new SCryptPasswordEncoder());
// md
// encoders.put("md4", new Md4PasswordEncoder());
// encoders.put("md5", new MessageDigestPasswordEncoder("MD5"));
// sha
// encoders.put("sha1", new StandardPasswordEncoder("SHA-1", ""));
// encoders.put("sha256", new StandardPasswordEncoder());
// encoders.put("sha384", new StandardPasswordEncoder("SHA-384", ""));
// encoders.put("sha512", new StandardPasswordEncoder("SHA-512", ""));
// sm3
// encoders.put("sm3", new SM3PasswordEncoder());
// ldap
// encoders.put("ldap", new LdapShaPasswordEncoder());

//idForEncode is default for encoder
DelegatingPasswordEncoder delegating = new DelegatingPasswordEncoder(bcrypt, encoders);
// 如果都不匹配以上加密方式,则使用默认方式
delegating.setDefaultPasswordEncoderForMatches(encoder);
return delegating;
}
  • 本文作者: forever杨
  • 本文链接: https://blog.yl-online.top/posts/583c9124.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。如果文章内容对你有用,请记录到你的笔记中。本博客站点随时会停止服务,请不要收藏、转载!