首页 > 解决方案 > “WARN osscbcrypt.BCryptPasswordEncoder - Spring Security 中的空编码密码”是什么意思?

问题描述

我正在现有的 Web 应用程序中实现 Spring Security,当我尝试登录时,我得到的响应是错误的凭据(即使凭据是正确的)当我尝试查看日志时,我得到了一些东西

警告 osscbcrypt.BCryptPasswordEncoder - 空编码密码

这是不良凭证的原因吗?

这是我的代码

  @PostConstruct
public void init() {
    try {
        authenticationManagerBuilder
            .userDetailsService(accountDetailsService)
            .passwordEncoder(passwordEncoder());
    } catch (Exception e) {
        throw new BeanInitializationException("Security configuration failed", e);
    }
}


 @Bean
public PasswordEncoder passwordEncoder() 
{
    return new BCryptPasswordEncoder();
}

提前致谢 !!

标签: javaspring-bootspring-securityjwt

解决方案


从字面上看,它的意思是它所说的。如有类似疑问,请查看源代码。

下面的代码来自package org.springframework.security.crypto.bcrypt;

public boolean matches(CharSequence rawPassword, String encodedPassword) {
    if (encodedPassword == null || encodedPassword.length() == 0) {
        logger.warn("Empty encoded password");
        return false;
    }
    if (!BCRYPT_PATTERN.matcher(encodedPassword).matches()) {
        logger.warn("Encoded password does not look like BCrypt");
        return false;
    }
    return BCrypt.checkpw(rawPassword.toString(), encodedPassword);
}

如你看到的:

编码密码 == 空 || 编码密码.length() == 0

因此你的警告。


推荐阅读