shiro中密码匹配

来源:互联网 发布:如何关闭mac日历 编辑:程序博客网 时间:2024/05/18 01:11

参考文章http://jinnianshilongnian.iteye.com/blog/2029717


Shiro通过在配置文件汇总进行如下配置进行密码匹配

<!-- 凭证匹配器 -->

    <bean id="credentialsMatcher" class="com.github.zhangkaitao.shiro.chapter12.credentials.RetryLimitHashedCredentialsMatcher">        <constructor-arg ref="cacheManager"/>        <property name="hashAlgorithmName" value="md5"/>        <property name="hashIterations" value="2"/>        <property name="storedCredentialsHexEncoded" value="true"/>    </bean>


<property name="hashAlgorithmName" value="md5"/>指定hash算法为MD5;<property name="hashIterations" value="2"/>指定散列次数为2次;<pre name="code" class="html"><property name="storedCredentialsHexEncoded" value="true"/>指定Hash散列值使用Hex加密存储。value="false"表明hash散列值用用Base64-encoded存储。

需要注意:

数据库密码存储时使用的加密方式要和配置文件中配置的方式相一致。如以上配置,那么数据库密码加密就要使用如下方式:

String password =  new SimpleHash("md5","123456",ByteSource.Util.bytes("adminnull"),2).toHex();
public SimpleHash(String algorithmName, Object source, Object salt, int hashIterations) 四个参数分别标识算法名称,散列对象,散列使用的salt值,散列次数。

0 0
原创粉丝点击