一般的用户登录密码都是MD5加密的了,算是标配吧。本文说的是自定义一个ShiroDbRealm,然后把shiro自带的HashedCredentialsMatcher给set进去。
当然你可以自己扩展。
<bean id="shiroDbRealm" class="xxx.ShiroDbRealm">
<constructor-arg index="0" name="cacheManager" ref="shiroJedisCacheManager"/>
<!-- 启方式1 -->
<!-- <constructor-arg index="1" name="matcher" ref="credentialsMatcher"/>-->
<!-- 启用身份验证缓存,即缓存AuthenticationInfo信息,默认false -->
<property name="authenticationCachingEnabled" value="false"/>
<!-- 缓存AuthenticationInfo信息的缓存名称 -->
<property name="authenticationCacheName" value="authenticationCache"/>
<!-- 缓存AuthorizationInfo信息的缓存名称 -->
<property name="authorizationCacheName" value="authorizationCache"/>
<!-- 启方式1 -->
<property name="credentialsMatcher" ref="credentialsMatcher"/>
</property>
</bean>
<bean id="credentialsMatcher" class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
<constructor-arg index="0" value="md5"/>
<!-- 迭代次数默认1 -->
<property name="hashIterations" value="1"/>
</bean>
来源:oschina
链接:https://my.oschina.net/osokra/blog/4458813