所以这是我的第一个代码
@Autowired
protected void configureGlobal(AuthenticationManagerBuilder registry) throws Exception {
registry.userDetailsService(userDetailsService);
}
我想使用密码编码器,所以我将代码转换为
@Autowired
protected void configureGlobal(AuthenticationManagerBuilder registry) throws Exception {
ShaPasswordEncoder sha= new ShaPasswordEncoder(256);
registry.userDetailsService(userDetailsService).passwordEncoder(sha);
}
但它仍然无法工作..这段代码似乎有什么问题?我很新的java配置..我希望有人可以帮助我..
答案 0 :(得分:0)
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(user.getPassword().getBytes());
byte byteData[] = md.digest();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < byteData.length; i++) {
sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16)
.substring(1));
}
user.setPassword(sb.toString());