(资料图片)
SpringBoot 集成 Security 时,报 Encoded password does not look like BCrypt
原因:SecurityConfig 必须 Bean 的形式实例化
/** * 配置用户身份的configure()方法 * * @param auth * @throws Exception */@Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder());}
解决方案
/** * 强散列哈希加密实现 * 必须 Bean 的形式实例化,否则会报 :Encoded password does not look like BCrypt */@Beanpublic BCryptPasswordEncoder bCryptPasswordEncoder(){ return new BCryptPasswordEncoder();}/** * 配置用户身份的configure()方法 * * @param auth * @throws Exception */@Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());}