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

+ 6 - 1
src/utils/cryptoJSMi.js

@@ -14,11 +14,16 @@ export const cyptoTool = {
14
   methods: {
14
   methods: {
15
     // 加密
15
     // 加密
16
     encrypt(word) {
16
     encrypt(word) {
17
+      let srcs = null
17
       let CRYPTOJSKEY = '1234567890123456'
18
       let CRYPTOJSKEY = '1234567890123456'
18
       let CRYPTOJSIV = '1234567890123456'
19
       let CRYPTOJSIV = '1234567890123456'
19
       let key = CryptoJS.enc.Utf8.parse(CRYPTOJSKEY);
20
       let key = CryptoJS.enc.Utf8.parse(CRYPTOJSKEY);
20
       let iv = CryptoJS.enc.Utf8.parse(CRYPTOJSIV);
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
       let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
27
       let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
23
       return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
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
   // baseURL: "http://192.168.3.142:8080/api",
24
   // baseURL: "http://192.168.3.142:8080/api",
25
   // baseURL: "http://192.168.3.90:8080/api",
25
   // baseURL: "http://192.168.3.90:8080/api",
26
   // baseURL: "http://172.16.100.153:8081/api",
26
   // baseURL: "http://172.16.100.153:8081/api",
27
+  // baseURL: "http://192.168.97.176:8081/api",
27
   // baseURL: "http://j41711d831.wicp.vip/api",
28
   // baseURL: "http://j41711d831.wicp.vip/api",
28
   // 超时
29
   // 超时
29
   timeout: 10000
30
   timeout: 10000