zoukankan      html  css  js  c++  java
  • SimpleCredentialsMatcher和HashedCredentialsMatcher的区别

    如果不知道shiro的认证过程,可以先看这篇文章:https://blog.csdn.net/ITWANGBOIT/article/details/102500492

    1:它们都是CredentialsMatcher的实现类,而且HashedCredentialsMatcher还是SimpleCredentialsMatcher的子类

    2:SimpleCredentialsMatcher进行的是明文密码的比对。

    (1)AuthenticatingRealm的doGetAuthenticationInfo方法返回的AuthenticationInfo对象中除了principal和realmName外,只有密码凭据,且为明文密码。

    (2)比对宗旨:仅仅是从token和info中获取明文密码进行比对

    3:HashedCredentialsMatcher进行的是加盐密文密码的比对。

    (1)保存密码时,进行的加密如下

    (2)我们在创建HashedCredentialsMatcher时,要给其设置hash算法和hash的次数(和加密密码时使用的hash算法和hash次数要一致)。

    (3)AuthenticatingRealm的doGetAuthenticationInfo方法返回的AuthenticationInfo对象中除了principal和realmName外,还有加密密文密码凭据和当时所用的盐。

    (4)token中是用户输入的明文密码,info里是事先保存的密文密码和盐;

    比对宗旨是:借助给HashedCredentialsMatcher设置的hash算法和hash次数,将token中的明文密码用info中的盐进行加密,代码第381行就是将加密之后得到的密文密码和info中的密文密码进行比对。

    代码第405行是获取info中的盐,第412行是将token中的明文密码,info中的盐,和事先设置的hash次数一起传递给另一个方法(加密的方法)

    代码第444行是获取事先设置的hash算法,第445行是拿着四个参数进行加密。

  • 相关阅读:
    Found class xxx.xxx.xxx, but interface was expected
    String的length()和getBytes().length
    springboot shutdown(停机)
    关于Java代码简化的小技巧
    数据库的简单查询
    数据库TSQL语句
    环境搭建及wamp空密码修改
    js windows对象
    JS函数的其他用法【备于取用】
    js递归
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13302481.html
Copyright © 2011-2022 走看看