当前位置: 首页 > news >正文

org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder

密码,加密,解密

spring-security-crypto-5.7.3.jar

/** Copyright 2002-2011 the original author or authors.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**      https://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package org.springframework.security.crypto.bcrypt;import java.security.SecureRandom;
import java.util.regex.Matcher;
import java.util.regex.Pattern;import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;import org.springframework.security.crypto.password.PasswordEncoder;/*** Implementation of PasswordEncoder that uses the BCrypt strong hashing function. Clients* can optionally supply a "version" ($2a, $2b, $2y) and a "strength" (a.k.a. log rounds* in BCrypt) and a SecureRandom instance. The larger the strength parameter the more work* will have to be done (exponentially) to hash the passwords. The default value is 10.** @author Dave Syer*/
public class BCryptPasswordEncoder implements PasswordEncoder {private Pattern BCRYPT_PATTERN = Pattern.compile("\\A\\$2(a|y|b)?\\$(\\d\\d)\\$[./0-9A-Za-z]{53}");private final Log logger = LogFactory.getLog(getClass());private final int strength;private final BCryptVersion version;private final SecureRandom random;public BCryptPasswordEncoder() {this(-1);}/*** @param strength the log rounds to use, between 4 and 31*/public BCryptPasswordEncoder(int strength) {this(strength, null);}/*** @param version the version of bcrypt, can be 2a,2b,2y*/public BCryptPasswordEncoder(BCryptVersion version) {this(version, null);}/*** @param version the version of bcrypt, can be 2a,2b,2y* @param random the secure random instance to use*/public BCryptPasswordEncoder(BCryptVersion version, SecureRandom random) {this(version, -1, random);}/*** @param strength the log rounds to use, between 4 and 31* @param random the secure random instance to use*/public BCryptPasswordEncoder(int strength, SecureRandom random) {this(BCryptVersion.$2A, strength, random);}/*** @param version the version of bcrypt, can be 2a,2b,2y* @param strength the log rounds to use, between 4 and 31*/public BCryptPasswordEncoder(BCryptVersion version, int strength) {this(version, strength, null);}/*** @param version the version of bcrypt, can be 2a,2b,2y* @param strength the log rounds to use, between 4 and 31* @param random the secure random instance to use*/public BCryptPasswordEncoder(BCryptVersion version, int strength, SecureRandom random) {if (strength != -1 && (strength < BCrypt.MIN_LOG_ROUNDS || strength > BCrypt.MAX_LOG_ROUNDS)) {throw new IllegalArgumentException("Bad strength");}this.version = version;this.strength = (strength == -1) ? 10 : strength;this.random = random;}@Overridepublic String encode(CharSequence rawPassword) {if (rawPassword == null) {throw new IllegalArgumentException("rawPassword cannot be null");}String salt = getSalt();return BCrypt.hashpw(rawPassword.toString(), salt);}private String getSalt() {if (this.random != null) {return BCrypt.gensalt(this.version.getVersion(), this.strength, this.random);}return BCrypt.gensalt(this.version.getVersion(), this.strength);}@Overridepublic boolean matches(CharSequence rawPassword, String encodedPassword) {if (rawPassword == null) {throw new IllegalArgumentException("rawPassword cannot be null");}if (encodedPassword == null || encodedPassword.length() == 0) {this.logger.warn("Empty encoded password");return false;}if (!this.BCRYPT_PATTERN.matcher(encodedPassword).matches()) {this.logger.warn("Encoded password does not look like BCrypt");return false;}return BCrypt.checkpw(rawPassword.toString(), encodedPassword);}@Overridepublic boolean upgradeEncoding(String encodedPassword) {if (encodedPassword == null || encodedPassword.length() == 0) {this.logger.warn("Empty encoded password");return false;}Matcher matcher = this.BCRYPT_PATTERN.matcher(encodedPassword);if (!matcher.matches()) {throw new IllegalArgumentException("Encoded password does not look like BCrypt: " + encodedPassword);}int strength = Integer.parseInt(matcher.group(2));return strength < this.strength;}/*** Stores the default bcrypt version for use in configuration.** @author Lin Feng*/public enum BCryptVersion {$2A("$2a"),$2Y("$2y"),$2B("$2b");private final String version;BCryptVersion(String version) {this.version = version;}public String getVersion() {return this.version;}}}

相关文章:

org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder

密码&#xff0c;加密&#xff0c;解密 spring-security-crypto-5.7.3.jar /** Copyright 2002-2011 the original author or authors.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with t…...

系统安全测试要怎么做?

进行系统安全测试时&#xff0c;可以按照以下详细的步骤进行&#xff1a; 1、信息收集和分析&#xff1a; 收集系统的相关信息&#xff0c;包括架构、部署环境、使用的框架和技术等。 分析系统的安全需求、威胁模型和安全策略等文档。 2、威胁建模和风险评估&#xff1a; …...

Golang并发模型:Goroutine 与 Channel 初探

文章目录 goroutinegoexit() channel缓冲closerangeselect goroutine goroutine 是 Go 语言中的一种轻量级线程&#xff08;lightweight thread&#xff09;&#xff0c;由 Go 运行时环境管理。与传统的线程相比&#xff0c;goroutine 的创建和销毁的开销很小&#xff0c;可以…...

批量添加PPT备注

我一直都觉得&#xff0c;用python高效办公&#xff0c;是件没必要的事。。。 但直到最近写课做PPT&#xff0c;做了80多页PPT&#xff0c;要把每一页PPT的备注粘贴进去时 我觉得&#xff0c;有什么关系呢&#xff0c;一页一页粘 但是粘到5页&#xff0c;我感觉ctlc\v频率有点儿…...

数据挖掘之PCA-主成分分析

PCA的用处&#xff1a;找出反应数据中最大变差的投影&#xff08;就是拉的最开&#xff09;。 在减少需要分析的指标同时&#xff0c;尽量减少原指标包含信息的损失&#xff0c;以达到对所收集数据进行全面分析的目的 但是什么时候信息保留的最多呢&#xff1f;具体一点&#…...

人工智能-注意力机制之注意力汇聚:Nadaraya-Watson 核回归

查询&#xff08;自主提示&#xff09;和键&#xff08;非自主提示&#xff09;之间的交互形成了注意力汇聚&#xff1b; 注意力汇聚有选择地聚合了值&#xff08;感官输入&#xff09;以生成最终的输出。 本节将介绍注意力汇聚的更多细节&#xff0c; 以便从宏观上了解注意力机…...

<HarmonyOS第一课>1·运行Hello World【课后考核】

【习题】运行Hello World工程 判断题 1.DevEco Studio是开发HarmonyOS应用的一站式集成开发环境。 正确(True) 2.main_pages.json存放页面page路径配置信息。 正确(True) 单选题 1.在stage模型中&#xff0c;下列配置文件属于AppScope文件夹的是&#xff1f;&#xff08;…...

Ubuntu18.04安装A-Loam保姆级教程

系统环境&#xff1a;Ubuntu18.04.6 LTS 1.A-Loam的安装前要求&#xff1a; 1.1 ROS安装&#xff1a;参考我的另一篇博客 Ubuntu18.04安装ROS-melodic保姆级教程_灬杨三岁灬的博客-CSDN博客还是那句话&#xff0c;有时候加了这行也不好使&#xff0c;我是疯狂试了20次&#…...

重生之我是一名程序员 40 ——字符串函数(1)

哈喽啊大家晚上好&#xff01;今天呢给大家带来点新的东西——字符串函数strcpy。 首先&#xff0c;让我来给大家介绍一下它。strcpy函数是C语言中的一个字符串函数&#xff0c;用于将一个字符串复制到另一个字符串中。其函数原型为&#xff1a; char* strcpy(char* dest, co…...

Navicat 技术指引 | 连接 GaussDB 主备版

Navicat Premium&#xff08;16.2.8 Windows版或以上&#xff09; 已支持对GaussDB 主备版的管理和开发功能。它不仅具备轻松、便捷的可视化数据查看和编辑功能&#xff0c;还提供强大的高阶功能&#xff08;如模型、结构同步、协同合作、数据迁移等&#xff09;&#xff0c;这…...

【git】pip install git+https://github.com/xxx/xxx替换成本地下载编译安装解决网络超时问题

目录 &#x1f311;&#x1f311; 背景 &#x1f312; &#x1f312;作用 &#x1f314;&#x1f314; 问题 &#x1f314;&#x1f314;解决方案 &#x1f319;方法一 &#x1f319;方法二 &#x1f31d;&#x1f31d;我的解决方案 整理不易&#xff0c;欢迎一键三连…...

SQL Server对象类型(6)——4.6.存储过程和函数(Procedure和Function)

4.6. 存储过程和函数(Procedure和Function) 4.6.1. 过程和函数概念 与Oracle中类似,SQL Server中,存储过程和函数都是虚的、被定义的代码对象,它们都是由一组T-SQL或公共语言运行库(CLR)代码构成的程序,其本身并不存储数据,通过数据库或应用端调用等方式来运行,以满…...

spring @Async异步执行

在一些后台耗时的场景比如说生成统计报表&#xff0c;生成数据文件&#xff0c;执行批量任务时候&#xff0c;需要异步执行&#xff0c;先登记信息&#xff0c;然后异步执行批量同步返回给客户端。在spring中要想使用异步方法执行&#xff0c;必须使用EnableAsync注解开启async…...

#Js篇:单线程模式同步任务异步任务任务队列事件循环setTimeout() setInterval()

单线程模式 之所以采用单线程&#xff0c;而不是多线程&#xff0c;跟历史有关系。原因是不想让浏览器变得太复杂&#xff0c;因为多线程需要共享资源、且有可能修改彼此的运行结果&#xff0c;对于一种网页脚本语言来说&#xff0c;太复杂了。 好处 实现起来比较简单&#…...

html table样式的设计 表格边框修饰

<!DOCTYPE html> <html> <head> <meta http-equiv"Content-Type" content"text/html; charsetutf-8" /> <title>今日小说排行榜</title> <style> table {border-collapse: collapse;border: 4px double red; /*…...

2023年【危险化学品经营单位安全管理人员】考试内容及危险化学品经营单位安全管理人员最新解析

题库来源&#xff1a;安全生产模拟考试一点通公众号小程序 危险化学品经营单位安全管理人员考试内容是安全生产模拟考试一点通生成的&#xff0c;危险化学品经营单位安全管理人员证模拟考试题库是根据危险化学品经营单位安全管理人员最新版教材汇编出危险化学品经营单位安全管…...

腾讯云 小程序 SDK对象存储 COS使用记录,原生小程序写法。

最近做了一个项目&#xff0c;需求是上传文档&#xff0c;文档类型多种&#xff0c;图片&#xff0c;视频&#xff0c;文件&#xff0c;doc,xls,zip,txt 等等,而且文档类型可能是大文件&#xff0c;可能得上百兆&#xff0c;甚至超过1G。 腾讯云文档地址&#xff1a;https://c…...

【uniapp】本地资源图片无法通过 WXSS 获取,可以使用网络图片,或者 base64,或者使用image标签

uniapp开发 微信小程序 本地资源图片无法通过 WXSS 获取&#xff0c;可以使用网络图片&#xff0c;或者 base64&#xff0c;或者使用image标签。_uniapp 中的本地资源图片无法通过 wxss 获取,可以使用网络图片,或者 base64,或者_芒果大胖砸的博客-CSDN博客...

深入了解Spring Cloud中的分布式事务解决方案

引言 介绍分布式系统中事务管理的重要性&#xff0c;以及在云计算环境下分布式事务所面临的挑战。 传统事务和分布式事务 解释本地事务与分布式事务的区别&#xff0c;以及为什么在分布式环境中需要特殊的事务管理机制。 分布式事务的挑战 探讨在分布式系统中实现事务一致性所…...

安装compiler version 5

这个compiler version5 在我的资源里面可以免费下载&#xff1b; 另外这个东西还需要安装&#xff0c;安装教程在这里&#xff1a;Keil最新版保姆教程&#xff08;解决缺少V5编译器问题&#xff09; - 哔哩哔哩 (bilibili.com) 看吧安装好了year...

300+款RPG Maker插件终极指南:从零开始打造专业级游戏

300款RPG Maker插件终极指南&#xff1a;从零开始打造专业级游戏 【免费下载链接】RPGMakerMV RPGツクールMV、MZで動作するプラグインです。 项目地址: https://gitcode.com/gh_mirrors/rp/RPGMakerMV 想要快速提升RPG Maker游戏开发效率吗&#xff1f;这个开源项目提供…...

保姆级教程:用ESP32-CAM和Blinker App,5分钟搭建你的第一个无线监控(附常见上传失败解决方案)

零基础玩转ESP32-CAM&#xff1a;从开箱到手机监控的完整避坑指南 第一次拿到ESP32-CAM这个小玩意儿时&#xff0c;我盯着它看了半天——这真的能变成监控摄像头&#xff1f;作为一个连电阻电容都分不清的纯小白&#xff0c;我花了整整三天时间才让手机成功显示出画面。现在回想…...

如何在OBS Studio中构建专业级NDI网络视频传输系统:DistroAV终极配置指南

如何在OBS Studio中构建专业级NDI网络视频传输系统&#xff1a;DistroAV终极配置指南 【免费下载链接】obs-ndi DistroAV (formerly OBS-NDI): NDI integration for OBS Studio 项目地址: https://gitcode.com/gh_mirrors/ob/obs-ndi 在当今专业视频制作和直播领域&…...

在Ubuntu 18.04上,如何解决UE4.22编译时‘Running UnrealHeaderTool CrashReportClient’的报错?

在Ubuntu 18.04上解决UE4.22编译时‘Running UnrealHeaderTool CrashReportClient’报错的完整指南 第一次在Linux环境下编译Unreal Engine 4&#xff08;UE4&#xff09;就像尝试在陌生的厨房做一道复杂的料理——即使按照菜谱一步步操作&#xff0c;也可能因为环境差异而遇到…...

终极网盘直链解析工具:八大平台一键获取高速下载链接

终极网盘直链解析工具&#xff1a;八大平台一键获取高速下载链接 【免费下载链接】Online-disk-direct-link-download-assistant 一个基于 JavaScript 的网盘文件下载地址获取工具。基于【网盘直链下载助手】修改 &#xff0c;支持 百度网盘 / 阿里云盘 / 中国移动云盘 / 天翼云…...

沐曦股份Day0适配阿里千问Qwen3.6-35B-A3B,与FlagOS合作实现模型多芯部署

阿里巴巴千问模型团队最新宣布&#xff0c;开源旗下多模态“智能体小钢炮” Qwen3.6-35B-A3B模型。沐曦股份与FlagOS合作&#xff0c;完成了该模型的Day0 适配。经测试&#xff0c;基于沐曦芯片&#xff0c;实现了“零代码修改”完成 Qwen3.6-35B-A3B 的推理部署及充分验证。这…...

如何防御SQL注入攻击_禁止应用账号执行DDL操作

根本原因是container响应式定宽而container-fluid需父容器无宽度限制&#xff1b;Bootstrap 5中其默认12px内边距导致不贴边&#xff0c;须用自定义CSS清除&#xff0c;且需排查viewport、全局样式及嵌套逻辑。为什么container在小屏上留白多&#xff0c;而container-fluid没效…...

5分钟快速上手:FigmaCN中文汉化插件完整使用指南

5分钟快速上手&#xff1a;FigmaCN中文汉化插件完整使用指南 【免费下载链接】figmaCN 中文 Figma 插件&#xff0c;设计师人工翻译校验 项目地址: https://gitcode.com/gh_mirrors/fi/figmaCN 还在为Figma的英文界面感到困扰吗&#xff1f;作为一名中文设计师&#xff…...

从应变电阻到精准读数:基于MicroPython的HX711传感器AIoT称重系统实践

1. 从金属变形到电信号&#xff1a;应变电阻的工作原理 当你用手指轻轻按压一块薄金属片时&#xff0c;能感觉到它微微弯曲的弹性。这种看似简单的物理现象&#xff0c;正是现代电子秤的核心技术基础。我去年为社区生鲜柜改造称重系统时&#xff0c;拆解过十几个不同品牌的传感…...

小红书数据采集终极指南:3天掌握高效爬虫实战技巧

小红书数据采集终极指南&#xff1a;3天掌握高效爬虫实战技巧 【免费下载链接】xhs 基于小红书 Web 端进行的请求封装。https://reajason.github.io/xhs/ 项目地址: https://gitcode.com/gh_mirrors/xh/xhs 想要从小红书平台获取有价值的数据&#xff0c;却总是被复杂的…...