BCryptPasswordEncoder加密

阅读: 评论:0

BCryptPasswordEncoder加密
和其他加密⽅式相⽐,BCryptPasswordEncoder有着它⾃⼰的优势所在,⾸先加密的hash值每次都不同,就像md5的盐值加密⼀样,只不过盐值加密⽤到了随机数,前者⽤到的是其内置的算法规则,毕竟随机数没有设合适的话还是有⼀定⼏率被攻破的。其次BCryptPasswordEncoder的⽣成加密存储串也有60位之多。最重要的⼀点是,md5的加密不是spring security所推崇的加密⽅式了,所以我们还是要多了解点新的加密⽅式。
第⼀步。导⼊spring的相关依赖包,包括spring security的相关依赖包
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>地理位置服务
<artifactId>spring-security-config</artifactId>
</dependency>
因为BCryptPasswordEncoder加密的来源就是spring security中的⼀部分,所以这两个包⽐较重要。
其次就开始使⽤,记住要使⽤spring.security下的,不要选错。
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String password = Password());
seller.setPassword(password);
水玻璃铸造这是我截取的⼀部分代码中的⽚段,通过传⼊的值进⾏BCryptPasswordEncoder加密,然后获取,再保存。最后的格式是这样的,
电脑备用电源
其实下⽅的加密密⽂都是123456,但是由于每次的hash值都不同,导致加密密⽂都不⼀样,其实这才是我们所希望看到的,⽽不是千篇⼀律。
但是我们要考虑⼀个问题,通过加密密⽂后,密码可以加密了,但是我们会发现输⼊123456的密码进⾏登录时登录不了的,为什么?因为它识别不了我们加密密⽂和明⽂之间的转换,你需要告诉spring,我已经将明⽂进⾏转换,怎么告诉呢?
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="/schema/security"
xmlns:beans="/schema/beans"
xmlns:dubbo="/schema/dubbo"
xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/schema/beans /schema/beans/spring-beans.xsd
/schema/dubbo /schema/dubbo/dubbo.xsd
/schema/security /schema/security/spring-security.xsd">
<!-- 设置页⾯不登陆也可以访问 -->
<http pattern="/*.html" security="none"></http>
<http pattern="/css/**" security="none"></http>
<http pattern="/img/**" security="none"></http>
<http pattern="/js/**" security="none"></http>
<http pattern="/plugins/**" security="none"></http>
<http pattern="/seller/add.do" security="none"></http>
<!-- 页⾯的拦截规则    use-expressions:是否启动SPEL表达式默认是true -->
<http use-expressions="false">
汽车电子调节器<!-- 当前⽤户必须有ROLE_USER的⾓⾊才可以访问根⽬录及所属⼦⽬录的资源 -->
<intercept-url pattern="/**" access="ROLE_SELLER"/>
<!-- 开启表单登陆功能 -->
<form-login  login-page="/shoplogin.html" default-target-url="/admin/index.html" authentication-failure-url="/shoplogin.html" always-use-default-target="true"/>  <csrf disabled="true"/>
<!-- 放⾏内置框架页 -->
<headers>
<frame-options policy="SAMEORIGIN"/>
</headers>
<logout/>
</http>
<!-- 认证管理器 -->阳极铜
<authentication-manager>
<authentication-provider user-service-ref="userDetailsService">
<password-encoder ref="passwordEncoding"></password-encoder>
</authentication-provider>
</authentication-manager>
<beans:bean id="userDetailsService" class="com.pinyougou.service.UserDetailsServiceImpl">
<beans:property name="sellerService" ref="sellerService"></beans:property>
</beans:bean>
<beans:bean id="passwordEncoding" class="org.pto.bcrypt.BCryptPasswordEncoder"></beans:bean>
<!-- 引⽤dubbo 服务代理-->陶瓷运输
<dubbo:application name="pinyougou-shop-web" />
<dubbo:registry address="zookeeper://192.168.25.130:2181"/>
<dubbo:reference id="sellerService" interface="com.pinyougou.sellergoods.service.SellerService"></dubbo:reference>
</beans:beans>
通过spring的注⼊的⽅式进⾏管理,告诉它我们采⽤的是这种加密⽅式,它就会将明⽂进⾏数据库判断,验证成功即可通过。

本文发布于:2023-05-20 20:58:32,感谢您对本站的认可!

本文链接:https://patent.en369.cn/patent/4/107346.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:加密   规则   登陆
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 369专利查询检索平台 豫ICP备2021025688号-20 网站地图