有一个注册用户的课程 `@服务 公共类UserServiceImpl实现UserService {
@Autowired
UserDAO userDAO;
@Autowired
private RoleDAO roleDAO;
@Autowired
private ShaPasswordEncoder shaPasswordEncoder;
@Override
public void save(User user) {
user.setPassword(shaPasswordEncoder.encodePassword(user.getPassword(),"mySalt"));
System.out.println(user.getPassword());
Set<Role> roles = new HashSet<>();
roles.add(roleDAO.getOne(1L));
user.setRoles(roles);
userDAO.save(user);
}
@Override
public User findByUsername(String username) {
return userDAO.findByUsername(username);
}
如你所见,我用盐在沙中编码 在这里我试图编码
@Bean
public ShaPasswordEncoder getShaPasswordEncoder(){
return new ShaPasswordEncoder();
}
@Autowired
public void registerGlobalAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsService)
.passwordEncoder(getShaPasswordEncoder());
}
所以我可以在哪里指定一个盐来解码密码
答案 0 :(得分:1)
您无法解码哈希密码。哈希函数是单向函数。因此,无法指定要解码的盐。