Browse Source

登录用户名和密码,添加rsa数据加密

DESKTOP-2K9OVK9\siwei 4 months ago
parent
commit
f1c2aa7c3a
2 changed files with 19 additions and 3 deletions
  1. 7 0
      src/utils/jsencrypt.js
  2. 12 3
      src/views/login.vue

+ 7 - 0
src/utils/jsencrypt.js

@@ -21,6 +21,13 @@ export function encrypt(txt) {
   return encryptor.encrypt(txt) // 对数据进行加密
 }
 
+// 加密
+export function encryptString(txt,publicKeyString) {
+  const encryptor = new JSEncrypt()
+  encryptor.setPublicKey(publicKeyString) // 设置公钥
+  return encryptor.encrypt(txt) // 对数据进行加密
+}
+
 // 解密
 export function decrypt(txt) {
   const encryptor = new JSEncrypt()

+ 12 - 3
src/views/login.vue

@@ -64,7 +64,7 @@
 <script>
 import { getCodeImg } from "@/api/login";
 import Cookies from "js-cookie";
-import { encrypt, decrypt } from '@/utils/jsencrypt'
+import { encrypt, decrypt, encryptString } from '@/utils/jsencrypt'
 
 export default {
   name: "Login",
@@ -92,7 +92,8 @@ export default {
       captchaEnabled: true,
       // 注册开关
       register: false,
-      redirect: undefined
+      redirect: undefined,
+      logingPublicKey:"",
     };
   },
   watch: {
@@ -114,6 +115,7 @@ export default {
         if (this.captchaEnabled) {
           this.codeUrl = "data:image/gif;base64," + res.img;
           this.loginForm.uuid = res.uuid;
+          this.logingPublicKey = res.publicKeyString;
         }
       });
     },
@@ -140,7 +142,14 @@ export default {
             Cookies.remove("password");
             Cookies.remove('rememberMe');
           }
-          this.$store.dispatch("Login", this.loginForm).then(() => {
+
+          const new_loginForm = {...this.loginForm};
+          const new_password = this.loginForm.password;
+          new_loginForm.password = encryptString(new_password,this.logingPublicKey);
+          const new_username = this.loginForm.username;
+          new_loginForm.username = encryptString(new_username,this.logingPublicKey);
+
+          this.$store.dispatch("Login", new_loginForm).then(() => {
             this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
           }).catch(() => {
             this.loading = false;