我在 Spring MVC 上开发了一个小项目。该项目有帐户表,帐户有一个使用 BCryptPasswordEncoder 编码的密码。 我使用了 java 配置而不是 XML 配置。
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
我获取用户信息并对密码进行编码。
@Autowired
private PasswordEncoder passwordEncoder;
String pass=user.getPassword();
user.setPassword(passwordEncoder.encode(pass));
最后,即使我使用 123 密码,它也会对它进行编码,但是,
boolean passstate=pe.matches(pass, user.getPassword());
返回错误
最佳答案
一个常见的错误是,“password”列(users表)的长度小于60,例如password VARCHAR(45),有些数据库会自动截断数据。因此,您总是会收到警告“编码的密码看起来不像 BCrypt”。
要解决此问题,请确保“密码”列的长度至少为 60。
更多详情请查看:https://www.mkyong.com/spring-security/spring-security-encoded-password-does-not-look-like-bcrypt/
关于java - Spring Security BCryptPasswordEncoder 已插入但不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44471587/