加匹配器到认证策略中
DefaultWebSecurityManager defaultWebSecurityManager=new DefaultWebSecurityManager();
//创建凭证匹配器
HashedCredentialsMatcher matcher=new HashedCredentialsMatcher();
//设置匹配器加密算法
matcher.setHashAlgorithmName("md5");
//设置匹配器迭代次数
matcher.setHashIterations(2);
//将匹配器注入到自定义认证策略中
myRealm.setCredentialsMatcher(matcher);
//获取用户信息
Object principal = token.getPrincipal();
//根据用户名获取数据库中用户信息
User user = userService.selUserInfoService((String) principal);
if(user!=null){
AuthenticationInfo info = new SimpleAuthenticationInfo(principal, user.getPwd(), ByteSource.Util.bytes(user.getUid()+""),user.getUname());
return info;
}
方法是讲前台数据传来的pwd通过md5加密与数据库中用户的加密后的密码进行对比

浙公网安备 33010602011771号