首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BCryptPasswordEncoder编码的密码看起来不像BCrypt

BCryptPasswordEncoder编码的密码看起来不像BCrypt
EN

Stack Overflow用户
提问于 2018-04-11 09:35:11
回答 1查看 7.1K关注 0票数 2

我有一个SpringBoot 2.0.1,2.0.1.RELEASE应用程序,下面是我的配置文件

代码语言:javascript
复制
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {


    @Autowired
    private Environment env;


    @Override
    protected void configure(HttpSecurity http) throws Exception {

        final List<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
        if (activeProfiles.contains("dev")) {
            http.csrf().disable();
            http.headers().frameOptions().disable();
        }

        http
                .authorizeRequests()
                .antMatchers(publicMatchers()).permitAll()
                .and()
                .formLogin().loginPage("/login").defaultSuccessUrl("/elcordelaciutat/config")
                .failureUrl("/login?error").permitAll()
                .and()
                .logout().permitAll();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

         PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
         UserDetails userDetails = User.withUsername("elcor")
                  .password(encoder.encode("elcor"))
                  .roles("ADMIN")
                  .build();
         auth.inMemoryAuthentication().withUser(userDetails);

    }


    private String[] publicMatchers() {

         /** Public URLs. */
        final String[] PUBLIC_MATCHERS = {
                "/webjars/**",
                "/css/**",
                "/js/**",
                "/images/**",
                "/",
                "/about/**",
                "/contact/**",
                "/error/**/*",
                "/console/**"
        };

        return PUBLIC_MATCHERS;

    }

}

但是,当我登录到应用程序时,我在日志文件中得到了以下消息:

代码语言:javascript
复制
2018-04-11 11:27  [http-nio-5678-exec-7] WARN  o.s.s.c.b.BCryptPasswordEncoder - Encoded password does not look like BCrypt

我不能记录in...and密码是正确的。在将我的应用程序从SpringBoot 1更新到SpringBoot 2后,出现了此错误

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-11 13:03:07

Security在版本5中引入了一些主要的更改,其中之一是在散列中包含用于散列密码的算法。这允许更容易的迁移。

密码的一般格式是:

代码语言:javascript
复制
{id}encodedPassword 

附带注意:如果您将密码存储在数据库中并设置了一个固定长度,这也会导致您意外地截断哈希的末尾,因为在它前面的id会增加哈希长度。

我还将一个项目从Spring 1/ Spring 4迁移到Spring 2/ Spring 5,并从BCrypt迁移到了PBKDF2。

我的密码编码器现在看起来如下:

代码语言:javascript
复制
public PasswordEncoder passwordEncoder() {
    // This is the ID we use for encoding.
    String currentId = "pbkdf2.2018";

    // List of all encoders we support. Old ones still need to be here for rolling updates
    Map<String, PasswordEncoder> encoders = new HashMap<>();
    encoders.put("bcrypt", new BCryptPasswordEncoder());
    encoders.put(currentId, new Pbkdf2PasswordEncoder(PBKDF2_2018_SECRET, PBKDF2_2018_ITERATIONS, PBKDF2_2018_HASH_WIDTH));

    return new DelegatingPasswordEncoder(currentId, encoders);
}

它还需要用{bcrypt}更新数据库,并在所有当前散列前缀中添加前缀(我以前只使用BCrypt )。

来源:春季博客

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49771558

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档