1、MD5加盐值进行加密处理
springsecurity.xml文件配置:(springsecurity.xml是spring安全的配置)
<authentication-manager>
<authentication-provider user-service-ref="loginService">
<password-encoder hash="md5">
<salt-source user-property="username" /><!-- username 密钥-->
</password-encoder>
</authentication-provider>
</authentication-manager>
直接配置 hash = 'md5' 等效于单独配置<bean id="encoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" />
这样,登录时输入的用户密码将会使用md5(加盐值)加密后与数据库里的密文进行匹配。
对应的MD5加密和匹配Java代码:
import org.springframework.security.authentication.enco