在前端 Vue.js 中,使用 `jsencrypt` 库对密码进行加密,并将加密后的密码发送给后端。

安装 `jsencrypt` 库
在你的 Vue.js 项目中运行以下命令来安装 `jsencrypt`:
bash
npm install jsencrypt --save

实现密码加密
// 引入 jsencrypt
import JSEncrypt from 'jsencrypt';
let Base64 = require("js-base64").Base64;

getPublicKey().then((resKey) => {
            const encrypt = new JSEncrypt(); // 初始化 JSEncrypt
            const publicKey = `${resKey.data}`; // 设置公钥(从后端获取并配置)
            encrypt.setPublicKey(publicKey);
            // 加密密码
            this.encryptedUsername = encrypt.encrypt(this.loginForm.username);
            this.encryptedPassword = encrypt.encrypt(this.loginForm.password);
            let postBody = {
              username: Base64.encode(this.encryptedUsername),
              password: Base64.encode(this.encryptedPassword),
            };
            loginCheck(postBody).then((res) => {
              this.phone = res.phoneNumber;
              this.openView = true;
              if (this.times == 60) {
                this.sendPhoneCode();
              } else {
                this.timer = setInterval(() => {
                  this.times--;
                  if (this.times === 0) {
                    this.codeFlag = false;
                    this.times = 60;
                    clearInterval(this.timer);
                  }
                }, 1000);
              }
            });
          });

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值