当前位置:   article > 正文

前端登录密码加密传输_如何解决登录密码明文传输问题

如何解决登录密码明文传输问题

前端安全检查系统漏洞处理

前端安全检查系统漏洞处理

1.密码明文传输

项目登陆时,登录接口使用post请求,密码没有加密,明文传输

本次使用的RAS加密,首先前端会有一个公钥,后端会有一个私钥,公钥和私钥都是后端生成的,一般是在登录页面请求后端的公钥接口,以校园安全检查页面为例

前端需要安装依赖 npm install jsencrypt

utils/jsencrypt.js

  1. import JSEncrypt from 'jsencrypt/bin/jsencrypt.min';
  2. // 加密
  3. export function encrypt(txt, publicKey) {
  4.     // console.log(txt, publicKey);
  5.     const encryptor = new JSEncrypt();
  6.     encryptor.setPublicKey(publicKey); // 设置公钥
  7.     // console.log(encryptor.encrypt(txt));
  8.     return encryptor.encrypt(txt); // 对数据进行加密
  9. }
  10. // 解密
  11. export function decrypt(txt, privateKey) {
  12.     const encryptor = new JSEncrypt();
  13.     encryptor.setPrivateKey(privateKey); // 设置私钥
  14.     return encryptor.decrypt(txt); // 对数据进行解密
  15. }

login.vue

  1. import { encrypt } from '@/utils/jsencrypt.js';
  2.   let data = {
  3.                         password: this.param.password,
  4.                         username: this.param.username,
  5.                         captchaCode: this.param.captchaCode,
  6.                         captchaId: this.param.captchaId,
  7.                         rsaToken: this.param.rsaToken,
  8.                         checked: this.param.checked
  9.                     };
  10.     data.password = encrypt(this.param.password, this.rsaKey);
  11.                     api.login(data)
  12.                         .then(//自己登录代码实现)

这样就完成了对于密码的加密

2. 存在暴力破解

因为系统登录页面没有添加验证码,所以解决方法是添加后端生成的图形验证码

3. 垂直越权

由于页面没有做对于页面的权限处理,导致可以通过页面输入地址强行进入,校园安全检查是通过路由守卫配合菜单数据来进行权限的处理,在跳转页面时判断如果这次跳转的地址不在菜单列表与白名单中,表示没有权限,以这种方法完成权限的处理

  1. const whiteIntercept=[
  2. //homePage ,
  3. //404'
  4. //login',
  5. //checkDetails',
  6. ...]
  7. function checkPath(data, path){for(const item of data){if(item.url === path||'/'+ item.url === path){
  8. return true;}
  9. if(item.children){if(checkPath(item.children, path)){return true;}}}
  10. return false;}

  1. router.beforeEach(async(to,from,next)=>{
  2. if(Token){
  3. if(authorityJudgment(to.path)){
  4. if(!user){
  5. store.dispatch("user/getUserInfo')}else {
  6. if(to.path==='/login'){next('/')}else {
  7. next()}}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/948397
推荐阅读
相关标签
  

闽ICP备14008679号