security 加密
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
</dependency>
这下面主要加密方式
public void register(UmsMember umsMember){
String encode = passwordEncoder.encode(umsMember.getPassword());
umsMember.setPassword(encode);
umsMemberMapper.insertUmsMember(umsMember);
}
配置Bean
在启动类中加上 PasswordEncoder 配置项
@SpringBootApplication
public class JwTappApplication {
public static void main(String[] args) {
SpringApplication.run(JwTappApplication.class, args);
}
@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> connector.setProperty("relaxedQueryChars", "|{}[]\\"));
return factory;
}
**@Bean
public PasswordEncoder passwordEncoder(){
// 通过passwordEncoder的实现类,实现加密算法
return new BCryptPasswordEncoder(10);
}**
}
上面方式只用passwordEncoder 来加密,存到数据库