Browse Source

feat(api): 增加通用型密码加密

gemercheung 3 years ago
parent
commit
1dc0d5fa67
4 changed files with 106 additions and 4 deletions
  1. 3 2
      src/api/sys/user.ts
  2. 99 0
      src/utils/encodeUtil.ts
  3. 1 0
      src/utils/http/axios/index.ts
  4. 3 2
      src/views/sys/login/LoginForm.vue

+ 3 - 2
src/api/sys/user.ts

@@ -1,6 +1,6 @@
 import { defHttp } from '/@/utils/http/axios';
 import { LoginParams, LoginResultModel, GetUserInfoModel } from './model/userModel';
-
+import { encodeStr } from '/@/utils/encodeUtil';
 import { ErrorMessageMode } from '/#/axios';
 
 enum Api {
@@ -15,8 +15,9 @@ enum Api {
  */
 export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
   const form = new FormData();
+  const encryptPassword: string = encodeStr(window.btoa(params.password));
   form.append('username', params.username);
-  form.append('password', params.password);
+  form.append('password', encryptPassword);
   form.append('captcha', params.captcha);
   return defHttp.post<LoginResultModel>(
     {

+ 99 - 0
src/utils/encodeUtil.ts

@@ -0,0 +1,99 @@
+/*
+ ** 登录密码加密
+  http://face3d.4dage.com:7005/4dzfb-2.0/shop/src/master/platform-admin/src/main/webapp/login.html
+ */
+function randomWord(randomFlag, min, max?) {
+  let str = '';
+  let range = min;
+  const arr = [
+    '0',
+    '1',
+    '2',
+    '3',
+    '4',
+    '5',
+    '6',
+    '7',
+    '8',
+    '9',
+    'a',
+    'b',
+    'c',
+    'd',
+    'e',
+    'f',
+    'g',
+    'h',
+    'i',
+    'j',
+    'k',
+    'l',
+    'm',
+    'n',
+    'o',
+    'p',
+    'q',
+    'r',
+    's',
+    't',
+    'u',
+    'v',
+    'w',
+    'x',
+    'y',
+    'z',
+    'A',
+    'B',
+    'C',
+    'D',
+    'E',
+    'F',
+    'G',
+    'H',
+    'I',
+    'J',
+    'K',
+    'L',
+    'M',
+    'N',
+    'O',
+    'P',
+    'Q',
+    'R',
+    'S',
+    'T',
+    'U',
+    'V',
+    'W',
+    'X',
+    'Y',
+    'Z',
+  ];
+  // 随机产生
+  if (randomFlag) {
+    range = Math.round(Math.random() * (max - min)) + min;
+  }
+  for (let i = 0; i < range; i++) {
+    const pos = Math.round(Math.random() * (arr.length - 1));
+    str += arr[pos];
+  }
+  return str;
+}
+
+export function encodeStr(str, strv = ''): string {
+  const NUM = 2;
+  const front = randomWord(false, 8);
+  const middle = randomWord(false, 8);
+  const end = randomWord(false, 8);
+
+  const str1 = str.substring(0, NUM);
+  const str2 = str.substring(NUM);
+
+  if (strv) {
+    const strv1 = strv.substring(0, NUM);
+    const strv2 = strv.substring(NUM);
+    return [front + str2 + middle + str1 + end, front + strv2 + middle + strv1 + end];
+  }
+
+  return front + str2 + middle + str1 + end;
+}

+ 1 - 0
src/utils/http/axios/index.ts

@@ -61,6 +61,7 @@ const transform: AxiosTransform = {
       if (typeof message === 'object' && Reflect.has(message, 'pageSize')) {
         return message;
       } else {
+        debugger;
         return result || data;
       }
     }

+ 3 - 2
src/views/sys/login/LoginForm.vue

@@ -128,6 +128,7 @@
   import { useUserStore } from '/@/store/modules/user';
   import { LoginStateEnum, useLoginState, useFormRules, useFormValid } from './useLogin';
   import { useDesign } from '/@/hooks/web/useDesign';
+
   //import { onKeyStroke } from '@vueuse/core';
 
   const ACol = Col;
@@ -149,8 +150,8 @@
 
   const formData = reactive({
     account: '17324327132',
-    // password: 'zfb123456',
-    password: 'USFf52nBZiMTIzNDU2WAJ7GAofemSXnYdUok',
+    password: 'zfb123456',
+    // password: encodeStr(window.btoa('zfb123456')),
     captcha: '',
   });