Python 官方文档:入门教程 => 点击学习
本文实例为大家分享了SpringBoot整合BCrypt实现密码加密的具体代码,供大家参考,具体内容如下 一. 首先在pom依赖中加入依赖: <!-- security依赖
本文实例为大家分享了SpringBoot整合BCrypt实现密码加密的具体代码,供大家参考,具体内容如下
<!-- 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>
package com.zzx;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
//获得BCrypt支持
@EnableScheduling
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
package com.zzx.test;
import org.springframework.security.crypto.bcrypt.BCryptPassWordEncoder;
public class BCryptTest {
public static void main(String[] args) {
//模拟从前端获得的密码
String password = "123456";
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
String newPassword = bCryptPasswordEncoder.encode(password);
System.out.println("加密的密码为: "+newPassword);
boolean same_password_result = bCryptPasswordEncoder.matches(password,newPassword);
//返回true
System.out.println("相同代码对比: "+same_password_result);
boolean other_password_result = bCryptPasswordEncoder.matches("1234456",newPassword);
//返回false
System.out.println("其他密码对比: " + other_password_result);
}
}
运行结果如下:
--结束END--
本文标题: SpringBoot整合BCrypt实现密码加密
本文链接: https://www.lsjlt.com/news/158539.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0