Browse Source

登录加密

李帅 2 months ago
parent
commit
5d4d1d6620
3 changed files with 12 additions and 2 deletions
  1. 5 1
      src/store/modules/user.js
  2. 6 1
      src/utils/cryptoJSMi.js
  3. 1 0
      src/utils/request.js

+ 5 - 1
src/store/modules/user.js

@@ -1,5 +1,7 @@
1 1
 import { login, logout, getInfo } from '@/api/login'
2 2
 import { getToken, setToken, removeToken } from '@/utils/auth'
3
+import {cyptoTool} from '@/utils/cryptoJSMi';
4
+
3 5
 
4 6
 const user = {
5 7
   state: {
@@ -48,9 +50,11 @@ const user = {
48 50
     // 登录
49 51
     Login({ commit }, userInfo) {
50 52
       const username = userInfo.username.trim()
51
-      const password = userInfo.password
53
+      const password = cyptoTool.methods.encrypt(userInfo.password)
54
+      // const password = userInfo.password
52 55
       const code = userInfo.code
53 56
       const uuid = userInfo.uuid
57
+
54 58
       return new Promise((resolve, reject) => {
55 59
         login(username, password, code, uuid).then(res => {
56 60
           setToken(res.token)

+ 6 - 1
src/utils/cryptoJSMi.js

@@ -14,11 +14,16 @@ export const cyptoTool = {
14 14
   methods: {
15 15
     // 加密
16 16
     encrypt(word) {
17
+      let srcs = null
17 18
       let CRYPTOJSKEY = '1234567890123456'
18 19
       let CRYPTOJSIV = '1234567890123456'
19 20
       let key = CryptoJS.enc.Utf8.parse(CRYPTOJSKEY);
20 21
       let iv = CryptoJS.enc.Utf8.parse(CRYPTOJSIV);
21
-      let srcs = CryptoJS.enc.Utf8.parse(JSON.stringify(word));
22
+      if(typeof word === 'string'){
23
+        srcs = CryptoJS.enc.Utf8.parse(word);
24
+      }else {
25
+        srcs = CryptoJS.enc.Utf8.parse(JSON.stringify(word));
26
+      }
22 27
       let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
23 28
       return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
24 29
     },

+ 1 - 0
src/utils/request.js

@@ -24,6 +24,7 @@ const service = axios.create({
24 24
   // baseURL: "http://192.168.3.142:8080/api",
25 25
   // baseURL: "http://192.168.3.90:8080/api",
26 26
   // baseURL: "http://172.16.100.153:8081/api",
27
+  // baseURL: "http://192.168.97.176:8081/api",
27 28
   // baseURL: "http://j41711d831.wicp.vip/api",
28 29
   // 超时
29 30
   timeout: 10000