spring boot security 项目中Encoded password does not look like BCrypt报错解决

以前pom.xml是这样的:


        org.springframework.boot
        spring-boot-starter-parent
        1.4.3.RELEASE
       
   

现在升级为


        org.springframework.boot
        spring-boot-starter-parent
        2.0.0.RELEASE
    

登录的时候,就会报错:Encoded password does not look like BCrypt

解决方法:

在public class WebSecurityConfig extends WebSecurityConfigurerAdapter 类中修改以下:

    @Bean
    UserDetailsService customUserService() {
        return new CustomUserService();
    }
    
    @Bean
	public BCryptPasswordEncoder passwordEncoder() {
		return new BCryptPasswordEncoder();
	}
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(customUserService()).passwordEncoder(passwordEncoder());

    }

更换旧密码的方法:

    @Test
	public void test89() {
		
		SysUser user = sysUserRepo.findByUsername("yourusername");
		
		BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
		// 加密
		String encodedPassword = passwordEncoder.encode(user.getPassword().trim());
		user.setPassword(encodedPassword);
		
		sysUserRepo.save(user);
    }

 

你可能感兴趣的:(spring-boot)