2 Commits 70294c7751 ... 3c15b84cf6

Auteur SHA1 Message Date
  sunxiao 3c15b84cf6 Merge branch '2024-10-24/fetaure-AES' il y a 3 semaines
  sunxiao 14d346221a feat: 新增密码加密 il y a 1 mois
2 fichiers modifiés avec 13 ajouts et 1 suppressions
  1. 1 0
      package.json
  2. 12 1
      src/store/modules/user.js

+ 1 - 0
package.json

@@ -24,6 +24,7 @@
     "@vueup/vue-quill": "1.2.0",
     "@vueuse/core": "10.6.1",
     "axios": "0.27.2",
+    "crypto-js": "^4.2.0",
     "echarts": "^5.5.0",
     "element-plus": "2.4.3",
     "file-saver": "2.0.5",

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

@@ -1,6 +1,17 @@
 import { login, logout, getInfo } from '@/api/login'
 import { getToken, setToken, removeToken } from '@/utils/auth'
 import defAva from '@/assets/images/profile.jpg'
+import CryptoJS from 'crypto-js';
+
+const SECRET_KEY = 'qwertasdfg159753'
+function AES_ECB_ENCRYPT(text) {
+  var keyHex = CryptoJS.enc.Utf8.parse(SECRET_KEY);
+  var messageHex = CryptoJS.enc.Utf8.parse(text);
+  var encrypted = CryptoJS.AES.encrypt(messageHex, keyHex, {
+    "mode": CryptoJS.mode.ECB
+  });
+  return encrypted.toString();
+}
 
 const useUserStore = defineStore(
   'user',
@@ -17,7 +28,7 @@ const useUserStore = defineStore(
       // 登录
       login(userInfo) {
         const username = userInfo.username.trim()
-        const password = userInfo.password
+        const password = AES_ECB_ENCRYPT(userInfo.password)
         const code = userInfo.code
         const uuid = userInfo.uuid
         return new Promise((resolve, reject) => {