shiro 加盐 构建 SimpleAuthenticationInfo
使用 ByteSource.Util.bytes(userInfo.getSalt()) 作为 盐 一定要和注册时保持一致
SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
userInfo, //用户名
userInfo.getPassword(), //密码
ByteSource.Util.bytes(userInfo.getSalt()),//salt=username+salt
getName() //realm name
);
注册用户 加密 simpleHash 作为保存密码
ByteSource bytes = ByteSource.Util.bytes(user.getSalt());
SimpleHash simpleHash = new SimpleHash("md5", user.getPassword(), bytes, 2);
另外 shiro 设置 加密校验方式 为了把前台传过来的参数 加密 然后与数据库数据进行比较
@Bean
public HashedCredentialsMatcher hashedCredentialsMatcher(){
HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
hashedCredentialsMatcher.setHashAlgorithmName("md5");//散列算法:这里使用MD5算法;
hashedCredentialsMatcher.setHashIterations(2);//散列的次数,比如散列两次,相当于
md5(md5(""));
return hashedCredentialsMatcher;
}
搞定!