3.9K Star 18.4K Fork 5.3K

卓源软件 / JeeSite 4.x and 5.x

 / 详情

shiro中使用MD5加密的时候,怎么取消自动加盐?

已完成
创建于  
2019-02-19 10:33

该问题是怎么引起的?

我旧数据是没有加盐过的MD5密码,因此在如下代码密码匹配不上,请问怎么取消shiro中的MD5加盐过程,有没有更好的解决办法,让两种密码形式同时存在?

AuthorizingRealm

	public static final String HASH_ALGORITHM = "MD5";
	public static final int HASH_INTERATIONS = 1;
	public static final int SALT_SIZE = 8;
	
	private UserService userService;
	
	public AuthorizingRealm() {
		super();
		// 设定密码校验的Hash算法与迭代次数
		HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(HASH_ALGORITHM);
		matcher.setHashIterations(HASH_INTERATIONS);
		matcher.setStoredCredentialsHexEncoded(true);
		this.setCredentialsMatcher(matcher);
	}

HashedCredentialsMatcher.class

    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        Object tokenHashedCredentials = this.hashProvidedCredentials(token, info);
        Object accountCredentials = this.getCredentials(info);
        return this.equals(tokenHashedCredentials, accountCredentials);
    }

    protected Object hashProvidedCredentials(AuthenticationToken token, AuthenticationInfo info) {
        Object salt = null;
        if (info instanceof SaltedAuthenticationInfo) {
            salt = ((SaltedAuthenticationInfo)info).getCredentialsSalt();
        } else if (this.isHashSalted()) {
            salt = this.getSalt(token);
        }

        return this.hashProvidedCredentials(token.getCredentials(), salt, this.getHashIterations());
    }

评论 (3)

菜徐鸭 创建了任务

是想用自己的加密方式吗?想用自己的话,就需要重写类,覆盖一下,自己写了。

@bei3ke 老哥,具体我要覆盖哪个类呢,能否告知一下,谢谢老哥

@jeeweb core项目,AuthorizingRealm 类

菜徐鸭 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
2339039 bei3ke 1578972268 1492440 jeeweb admin 1578952762
Java
1
https://gitee.com/thinkgem/jeesite4.git
git@gitee.com:thinkgem/jeesite4.git
thinkgem
jeesite4
JeeSite 4.x and 5.x

搜索帮助