数据库账号密码加密详解及实例
作者:lqh 时间:2024-01-22 14:41:43
数据库账号密码加密详解及实例
数据库中经常有对数据库账号密码的加密,但是碰到一个问题,在使用UserService对密码进行加密的时候,spring security 也是需要进行同步配置的,因为spring security 中验证的加密方式是单独配置的。如下:
<authentication-manager>
<authentication-provider user-service-ref="userDetailService">
<password-encoder ref="passwordEncoder" />
</authentication-provider>
</authentication-manager>
<beans:bean class="com.sapphire.security.MyPasswordEncoder" id="passwordEncoder">
<beans:constructor-arg value="md5"></beans:constructor-arg>
</beans:bean>
如上述配置文件所示,passwordEncoder才是在spring security对账号加密校验的地方。
spring security在拦截之后,会首先对用户进行查找,通过自己定义的userDetailService来找到对应的用户,然后由框架进行密码的匹配验证。
从userDetailService得到user以后,就会进入到DaoAuthenticationProvider中,这是框架中定义的 ,然后跳入其中的authenticate方法中。
该方法会进行两个检查,分别是
* preAuthenticationChecks : 主要进行的是对用户是否过期等信息的校验,调用的方法在userDetail中有定义的。
* additionalAuthenticationChecks : 这个就是用户名密码验证的过程了。
而PasswordEncoder是我们xml中注入的bean,所以了,我们调用的则是我们自己完成的passwordEncoder
public class MyPasswordEncoder extends MessageDigestPasswordEncoder {
public MyPasswordEncoder(String algorithm) {
super(algorithm);
}
@Override
public boolean isPasswordValid(String encPass, String rawPass, Object salt) {
return encPass.equals(DigestUtils.md5DigestAsHex(rawPass.getBytes()));
}
}
这是我对其实现的一个简单版本,调用的就是spring自带的加密算法,很简单了,当然也可以使用复杂的加密方法,这个就靠自己了
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
标签:数据库,账号密码,加密
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python numpy和list查询其中某个数的个数及定位方法
2021-04-29 01:36:50
Python自动创建Excel并获取内容
2023-12-31 01:42:07
![](https://img.aspxhome.com/file/2023/4/109574_0s.png)
CSS网页布局避免滥用DIV元素
2011-03-30 12:34:00
Python编程使用有限状态机识别地址有效性
2023-09-03 00:14:56
![](https://img.aspxhome.com/file/2023/2/133892_0s.jpg)
网页设计布局原则
2010-04-20 17:18:00
pandas dataframe添加表格框线输出的方法
2021-11-28 01:34:41
![](https://img.aspxhome.com/file/2023/8/118548_0s.jpg)
Python 调用有道翻译接口实现翻译
2023-03-11 06:35:34
![](https://img.aspxhome.com/file/2023/7/89197_0s.png)
python使用yield压平嵌套字典的超简单方法
2023-08-28 03:20:00
![](https://img.aspxhome.com/file/2023/0/93670_0s.jpg)
php中json 序列化为 [] 的弊端
2023-05-25 00:14:30
python strip() 函数和 split() 函数的详解及实例
2021-07-03 09:34:56
"模板化"——限制还是激发
2009-03-26 11:36:00
基于javascript实现tab切换特效
2024-02-24 12:31:58
![](https://img.aspxhome.com/file/2023/8/56478_0s.jpg)
一些CSS样式书写技巧
2007-10-16 12:57:00
Yii2基于Ajax自动获取表单数据的方法
2023-11-21 00:59:56
详解python列表生成式和列表生成式器区别
2021-09-13 16:15:14
Python通用循环的构造方法实例分析
2022-03-30 00:03:56
如何解决客户机页面刷新时连接不上数据库问题?
2009-12-16 18:24:00
Python实现爬取亚马逊数据并打印出Excel文件操作示例
2021-09-10 05:10:36
![](https://img.aspxhome.com/file/2023/3/105203_0s.png)
python常用web框架简单性能测试结果分享(包含django、flask、bottle、tornado)
2022-09-09 12:52:45
MySQL表设计优化与索引 (六)
2010-10-25 19:53:00