shiro中密码匹配

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

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

<span style="font-size:18px;"><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> </span>

<span style="font-size:18px;"><property name="hashAlgorithmName" value="md5"/>指定hash算法为MD5;  
<property name="hashIterations" value="2"/>指定散列次数为2次;
<property name="storedCredentialsHexEncoded" value="true"/>指定Hash散列值使用Hex加密存储。
value="false"表明hash散列值用用Base64-encoded存储。</span>

需要注意:

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

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