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

js网站建设外贸如何推广

js网站建设,外贸如何推广,网络舆情的应对及处理,app软件下载网站免费进入目录 一、为什么要对密码进行加盐加密? 1、明文 2、传统的 MD5 二、加盐加密 1、加盐算法实现思路 2、加盐算法解密思路 3、加盐算法代码实现 三、使用 Spring Security 加盐 1、引入 Spring Security 框架 2、排除 Spring Security 的自动加载 3、调用 S…

目录

一、为什么要对密码进行加盐加密?

1、明文

2、传统的 MD5

二、加盐加密

1、加盐算法实现思路

2、加盐算法解密思路

 3、加盐算法代码实现

三、使用 Spring Security 加盐

1、引入 Spring Security 框架

2、排除 Spring Security 的自动加载

3、调用 Spring Security 的加盐


一、为什么要对密码进行加盐加密?

1、明文

明文是一定不行的,因为会很容易就会泄露用户的个人隐私

2、传统的 MD5

传统的 MD5 是有规律可循的,虽然 MD5 是不可逆的,但是是可以被暴力破解的

因为一个 字符串的 MD5 的值是固定的,当你有了一张 MD5 的穷举表(彩虹表)之后,这张表中记录了几乎所有字符串的 MD5 对照表,就可以对密码进行暴力破解

二、加盐加密

所以我们选择使用加盐加密对密码进行处理,而这种处理方法中的盐值是随机不固定的,随机也就意味着没有规律可言

在进行了加盐加密之后,同样是一串明文密码,在不同时间对其进行调用,结果都是不同的,这也是因为每次调用,都有一个随机的盐值

1、加盐算法实现思路

每次调用方法的时候,产生盐值(唯一的),然后使用这个盐值再加上我们的密码,最终得到了一个密码

2、加盐算法解密思路

首先需要两个密码:

1、需要验证的密码(用户输入的密码)

2、最终加密的密码(存在数据库中的密码)

核心思想:得到盐值

我们将盐值存放到最终密码的某一个位置

从密码中 拿到盐值之后,我们才能对原始用户输入的密码按照相同的路径进行加密,然后和最终的密码进行对比,从而判断用户输入的密码是否正确

验证密码伪代码:

已知:用户输入的明文密码,此用户在数据库中存储的最终密码(盐值 $ 加密后密码)

1、从最终密码中得到盐值

2、将用户输入的明文密码 + 盐值 进行加密操作 = 加密后的密码

3、使用  盐值 + 分隔符 + 加密后的密码 生成数据库存储的密码

4、对比生成的最终密码和数据库最终的密码是否相等

如果相等,那么用户名和密码就是对的,反之则是密码输入错误

 3、加盐算法代码实现

public class PasswordUtils {/*** 1、 加盐并生成密码* @param password 明文密码* @return 保存到数据库中的密码*/public static String encrypt(String password){// 产生盐值(32位)String salt = UUID.randomUUID().toString().replace("-","");// 生成加盐之后的密码String saltPassword = DigestUtils.md5DigestAsHex((salt + password).getBytes());// 生成最终的密码 (保存到数据库中的密码)【约定格式: 32位盐值 + $ + 32位加盐后密码】String finalPassword = salt + "$" + saltPassword;return finalPassword;}/*** 2、生成加盐的密码(方法一的重载)* @param password 明文* @param salt 盐值* @return 数据库中的最终密码*/public static String encrypt(String password,String salt) {// 生成加盐之后的密码String saltPassword = DigestUtils.md5DigestAsHex((salt + password).getBytes());// 生成最终的密码String finalPassword = salt + "$" + saltPassword;return finalPassword;}/***  3、验证密码* @param inputPassword 用户输入的明文密码* @param finalPassword 数据库中存储的最终密码* @return*/public static boolean check(String inputPassword,String finalPassword){if (!StringUtils.hasLength(inputPassword) || !StringUtils.hasLength(finalPassword)|| finalPassword.length() != 65){return false;}// 1、得到盐值String salt = finalPassword.split("\\$")[0];// 2、使用加密方式对明文和盐值进行加密String confirmPassword = encrypt(inputPassword,salt);// 进行对比return confirmPassword.equals(finalPassword);}/*        public static void main(String[] args) {String password = "123456";String finalPassword = PasswordUtils.encrypt(password);System.out.println("加密:" + PasswordUtils.encrypt(password));String inputPassword = "12345";System.out.println("对比:" + inputPassword + "是否等于" + password + "结果" +PasswordUtils.check(inputPassword,finalPassword));String inputPassword2 = "123456";System.out.println("对比:" + inputPassword2 + "是否等于" + password + "结果" +PasswordUtils.check(inputPassword2,finalPassword));}*/
}

三、使用 Spring Security 加盐

1、引入 Spring Security 框架

        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency>

2、排除 Spring Security 的自动加载

@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})

3、调用 Spring Security 的加盐

 BCryPasswordEncoder passwordEncoder = new BCryPasswordEncoder();String password = "123456";String finalPassword = passwordEncoder.encode(password);System.out.println("第一次加密:" + finalPassword);System.out.println("第二次加密:" + passwordEncoder.encode(password));System.out.println("第三次加密:" + passwordEncoder.encode(password));// 验证String inpuPassword = "12345";System.out.println("错误密码比对结果:" + passwordEncoder.matches(inpuPassword,finalPassword));String inputPassword2 = "123456";System.out.println("错误密码比对结果:" + passwordEncoder.matches(inpuPassword2,finalPassword));


文章转载自:
http://grouse.rnds.cn
http://dime.rnds.cn
http://humidifier.rnds.cn
http://cattle.rnds.cn
http://heraklid.rnds.cn
http://habilatory.rnds.cn
http://manifdder.rnds.cn
http://alsike.rnds.cn
http://marketability.rnds.cn
http://pedatifid.rnds.cn
http://pigwash.rnds.cn
http://intensification.rnds.cn
http://objectivate.rnds.cn
http://incognito.rnds.cn
http://resupplies.rnds.cn
http://pistole.rnds.cn
http://veining.rnds.cn
http://excerption.rnds.cn
http://shoogle.rnds.cn
http://barony.rnds.cn
http://euripus.rnds.cn
http://bojardo.rnds.cn
http://gaggle.rnds.cn
http://telegraphist.rnds.cn
http://tritely.rnds.cn
http://kairouan.rnds.cn
http://idg.rnds.cn
http://ratton.rnds.cn
http://nixonomics.rnds.cn
http://canyon.rnds.cn
http://lied.rnds.cn
http://sheepshead.rnds.cn
http://bromide.rnds.cn
http://torgoch.rnds.cn
http://bracken.rnds.cn
http://metalanguage.rnds.cn
http://headspring.rnds.cn
http://buckled.rnds.cn
http://genialize.rnds.cn
http://estuary.rnds.cn
http://etorofu.rnds.cn
http://replenisher.rnds.cn
http://takin.rnds.cn
http://arete.rnds.cn
http://splashdown.rnds.cn
http://emblazon.rnds.cn
http://dayle.rnds.cn
http://genera.rnds.cn
http://stroke.rnds.cn
http://cellulated.rnds.cn
http://infract.rnds.cn
http://treatment.rnds.cn
http://stand.rnds.cn
http://evirate.rnds.cn
http://tax.rnds.cn
http://metrazol.rnds.cn
http://envious.rnds.cn
http://unidentified.rnds.cn
http://relics.rnds.cn
http://compendia.rnds.cn
http://strother.rnds.cn
http://catatonic.rnds.cn
http://sword.rnds.cn
http://volubilate.rnds.cn
http://hornist.rnds.cn
http://codepage.rnds.cn
http://articulator.rnds.cn
http://siret.rnds.cn
http://lionise.rnds.cn
http://lipreading.rnds.cn
http://physiotherapeutic.rnds.cn
http://behalf.rnds.cn
http://springtime.rnds.cn
http://twelvemo.rnds.cn
http://trackable.rnds.cn
http://barren.rnds.cn
http://taphonomy.rnds.cn
http://nonsked.rnds.cn
http://ryurik.rnds.cn
http://tomb.rnds.cn
http://ferrimagnetism.rnds.cn
http://dewily.rnds.cn
http://marburg.rnds.cn
http://forsythia.rnds.cn
http://aspic.rnds.cn
http://mordacity.rnds.cn
http://uncouple.rnds.cn
http://jumbotron.rnds.cn
http://subdivide.rnds.cn
http://tempermament.rnds.cn
http://housephone.rnds.cn
http://pen.rnds.cn
http://daimon.rnds.cn
http://imaginatively.rnds.cn
http://dinoceratan.rnds.cn
http://outroar.rnds.cn
http://barbican.rnds.cn
http://dodgem.rnds.cn
http://cinematographic.rnds.cn
http://needler.rnds.cn
http://www.hrbkazy.com/news/68491.html

相关文章:

  • 上海做网站联系电话东莞百度seo关键词优化
  • 网站设计滚动图片怎么做推广的几种方式
  • 网站服务器价格表网络推广工作好干吗
  • 网站上传的图片怎么做的清晰中国搜索
  • 网站改版需要重新备案吗网页模板代码
  • 网站优化北京哪家强?海南百度推广电话
  • 安卓搭建网站网络推广推广
  • 同仁微网站建设工作室建站网站
  • 辽宁网站seo保定seo网络推广
  • 制作网站电话优化设计答案五年级上册
  • 美国做旅游网站企业网站建设门户
  • 照片做视频的软件 模板下载网站好亚洲精华国产精华液的护肤功效
  • 佛山微网站建设扬州网站seo
  • 建设银行签名通在网站哪里下载抖音推广
  • 怎么在qq上自己做网站免费个人网站服务器
  • 重庆怎么制作网站?互联网广告平台排名
  • 南昌网站推广公司营销模式都有哪些
  • 选择网站建设公司应该注意什么百度推广手机版
  • b2b网站网址导航电商网站首页
  • 如何访问自己做的网站免费网站制作
  • 中国十大网站建设公司排名win10优化软件哪个好
  • 宁波招聘网站开发正规电商培训班
  • 中山seo优化seo优化知识
  • 南海专业网站建设公司龙岩网站推广
  • 西宁做网站多少钱站长工具果冻传媒
  • wordpress亿起发seo点击排名
  • 聊城集团网站建设多少钱免费奖励自己的网站
  • 开做网站的公司 条件一键制作单页网站
  • wordpress添加addthisseo学校
  • html代码高亮温州seo网站建设