SpringSecurity报:EncodedpassworddoesnotlooklikeBCrypt

博客 分享
0 149
张三
张三 2023-05-03 20:54:46
悬赏:0 积分 收藏

Spring Security 报:Encoded password does not look like BCrypt

SpringBoot 集成 Security 时,报 Encoded password does not look like BCrypt
原因:SecurityConfig 必须 Bean 的形式实例化

/**
 * 配置用户身份的configure()方法
 *
 * @param auth
 * @throws Exception
 */
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder());
}

解决方案

/**
 * 强散列哈希加密实现 
 * 必须 Bean 的形式实例化,否则会报 :Encoded password does not look like BCrypt
 */
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder()
{
    return new BCryptPasswordEncoder();
}

/**
 * 配置用户身份的configure()方法
 *
 * @param auth
 * @throws Exception
 */
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
}
posted @ 2023-05-03 20:46  VipSoft  阅读(11)  评论(0编辑  收藏  举报
回帖
    张三

    张三 (王者 段位)

    1111 积分 (2)粉丝 (41)源码

     

    温馨提示

    亦奇源码

    最新会员