springsecurity密码校验实现代码
时间: 2023-02-15 12:53:38 浏览: 95
Spring security密码加密实现代码实例
:
这是一段关于Spring Security密码校验实现的代码:
```
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/resources/**", "/registration").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
}
}
```
这段代码实现了Spring Security的密码校验功能,使用了BCryptPasswordEncoder类来对用户输入的密码进行加密,再与数据库存储的加密后的密码进行比对。
阅读全文