From 5889f0e30a0c59c7ed2f3888ca9265be8d6ca23e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Thu, 16 Mar 2023 23:27:29 +0800 Subject: [PATCH] login add salt --- frontend/vben/mock/sys/user.ts | 13 ++++++++++++- frontend/vben/package.json | 2 ++ frontend/vben/src/api/sys/model/userModel.ts | 4 ++++ frontend/vben/src/api/sys/user.ts | 9 +++++++++ frontend/vben/src/views/sys/login/LoginForm.vue | 5 ++++- 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/frontend/vben/mock/sys/user.ts b/frontend/vben/mock/sys/user.ts index 71e5874..b5900b5 100644 --- a/frontend/vben/mock/sys/user.ts +++ b/frontend/vben/mock/sys/user.ts @@ -1,4 +1,5 @@ import { MockMethod } from 'vite-plugin-mock' +import md5 from 'md5' import { resultError, resultSuccess, getRequestToken, requestParams } from '../_util' export function createFakeUserList() { @@ -60,6 +61,14 @@ const fakeCodeList: any = { '2': ['2000', '4000', '6000'], } export default [ + { + url: '/api/getLoginSalt', + timeout: 200, + method: 'get', + response: () => { + return resultSuccess({ salt: 'nc8w9f82hfioq2ci9hcwehcq' }) + }, + }, // mock user login { url: '/api/login', @@ -68,7 +77,9 @@ export default [ response: ({ body }) => { const { username, password } = body const checkUser = createFakeUserList().find( - (item) => item.username === username && password === item.password, + (item) => + item.username === username && + password === md5(item.password + 'nc8w9f82hfioq2ci9hcwehcq'), ) if (!checkUser) { return resultError('Incorrect account or password!') diff --git a/frontend/vben/package.json b/frontend/vben/package.json index 8d8baf5..7215220 100644 --- a/frontend/vben/package.json +++ b/frontend/vben/package.json @@ -53,6 +53,7 @@ "echarts": "^5.3.2", "intro.js": "^5.1.0", "lodash-es": "^4.17.21", + "md5": "^2.3.0", "mockjs": "^1.1.0", "nprogress": "^0.2.0", "path-to-regexp": "^6.2.0", @@ -81,6 +82,7 @@ "@types/inquirer": "^8.2.1", "@types/intro.js": "^3.0.2", "@types/lodash-es": "^4.17.6", + "@types/md5": "^2.3.2", "@types/mockjs": "^1.0.6", "@types/node": "^17.0.25", "@types/nprogress": "^0.2.0", diff --git a/frontend/vben/src/api/sys/model/userModel.ts b/frontend/vben/src/api/sys/model/userModel.ts index b97af3d..32f0096 100644 --- a/frontend/vben/src/api/sys/model/userModel.ts +++ b/frontend/vben/src/api/sys/model/userModel.ts @@ -67,3 +67,7 @@ export interface GetUserInfoModel { // 介绍 desc?: string } + +export interface GetLoginSaltModel { + salt: string +} diff --git a/frontend/vben/src/api/sys/user.ts b/frontend/vben/src/api/sys/user.ts index 168d488..2e6c0cf 100644 --- a/frontend/vben/src/api/sys/user.ts +++ b/frontend/vben/src/api/sys/user.ts @@ -7,11 +7,13 @@ import { RegisterParams, ResetPasswordResultModel, RegisterResultModel, + GetLoginSaltModel, } from './model/userModel' import { ErrorMessageMode } from '/#/axios' enum Api { + GetLoginSalt = '/getLoginSalt', Login = '/login', Logout = '/logout', ResetPassword = '/resetPassword', @@ -66,6 +68,13 @@ export function registerApi(params: RegisterParams, mode: ErrorMessageMode = 'mo ) } +/** + * @description: getLoginSalt + */ +export function getLoginSalt(username: string) { + return defHttp.get({ url: Api.GetLoginSalt, params: { username: username } }) +} + /** * @description: getUserInfo */ diff --git a/frontend/vben/src/views/sys/login/LoginForm.vue b/frontend/vben/src/views/sys/login/LoginForm.vue index efd2c98..84c8ac3 100644 --- a/frontend/vben/src/views/sys/login/LoginForm.vue +++ b/frontend/vben/src/views/sys/login/LoginForm.vue @@ -80,6 +80,7 @@