From e18022e00e9b919807aaf67a24737ca0ce00ed5f Mon Sep 17 00:00:00 2001 From: From-wh Date: Wed, 17 May 2023 10:47:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=90=8E=E5=8F=B0login=E5=8A=A0?= =?UTF-8?q?=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/admin/package-lock.json | 6 +++++ template/admin/package.json | 1 + .../src/components/verifition/utils/ase.js | 11 ++++++++++ .../admin/src/pages/account/login/index.vue | 6 ++++- template/admin/src/utils/ase.js | 22 +++++++++++++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 template/admin/src/utils/ase.js diff --git a/template/admin/package-lock.json b/template/admin/package-lock.json index 5f651f4a2..7a72ec076 100644 --- a/template/admin/package-lock.json +++ b/template/admin/package-lock.json @@ -15642,6 +15642,12 @@ "integrity": "sha1-a9KZwTsMRiay2iwDk81DhdYGrLk=", "dev": true }, + "jsencrypt": { + "version": "3.3.2", + "resolved": "https://registry.npmmirror.com/jsencrypt/-/jsencrypt-3.3.2.tgz", + "integrity": "sha512-arQR1R1ESGdAxY7ZheWr12wCaF2yF47v5qpB76TtV64H1pyGudk9Hvw8Y9tb/FiTIaaTRUyaSnm5T/Y53Ghm/A==", + "dev": true + }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmmirror.com/jsesc/-/jsesc-2.5.2.tgz", diff --git a/template/admin/package.json b/template/admin/package.json index db7647fa3..0fefd56df 100644 --- a/template/admin/package.json +++ b/template/admin/package.json @@ -100,6 +100,7 @@ "eslint-plugin-prettier": "^3.4.1", "eslint-plugin-vue": "^7.2.0", "iview-loader": "^1.3.0", + "jsencrypt": "^3.3.2", "less": "^2.7.3", "less-loader": "^4.1.0", "lint-staged": "^6.0.0", diff --git a/template/admin/src/components/verifition/utils/ase.js b/template/admin/src/components/verifition/utils/ase.js index 35290979e..5783a7679 100644 --- a/template/admin/src/components/verifition/utils/ase.js +++ b/template/admin/src/components/verifition/utils/ase.js @@ -9,3 +9,14 @@ export function aesEncrypt(word, keyWord = 'XwKsGlMcdPMEhR1B') { var encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); return encrypted.toString(); } + +/** + * @word hash256要加密的内容 + * @keyWord String 服务器随机返回的关键字 + * */ +export function aesEncryptHash(word, keyWord = 'XwKsGlMcdPMEhR1B') { + var key = CryptoJS.enc.Utf8.parse(keyWord); + var srcs = CryptoJS.enc.Utf8.parse(word); + var encrypted = CryptoJS.HmacSHA256(srcs, key); + return CryptoJS.enc.Hex.stringify(encrypted); +} diff --git a/template/admin/src/pages/account/login/index.vue b/template/admin/src/pages/account/login/index.vue index 42e191154..d62b1ff9e 100644 --- a/template/admin/src/pages/account/login/index.vue +++ b/template/admin/src/pages/account/login/index.vue @@ -75,6 +75,8 @@ import '@/assets/js/canvas-nest.min'; import Verify from '@/components/verifition/Verify'; import { PrevLoading } from '@/utils/loading.js'; import { formatFlatteningRoutes, findFirstNonNullChildren } from '@/libs/system'; +import { encryptWithKey } from '@/utils/ase.js'; + export default { components: { Verify, @@ -106,6 +108,7 @@ export default { key: '', copyright: '', version: '', + publicKey: '', }; }, created() { @@ -169,6 +172,7 @@ export default { this.swiperList = data.slide.length ? data.slide : [{ slide: this.defaultSwiperList }]; this.key = data.key; this.copyright = data.copyright; + this.publicKey = data.publicKey; this.version = data.version; this.login_captcha = data.login_captcha; }) @@ -192,7 +196,7 @@ export default { this.loading = true; AccountLogin({ account: this.formInline.username, - pwd: this.formInline.password, + pwd: encryptWithKey(this.formInline.password, this.publicKey), key: this.key, captchaType: 'blockPuzzle', captchaVerification: params ? params.captchaVerification : '', diff --git a/template/admin/src/utils/ase.js b/template/admin/src/utils/ase.js new file mode 100644 index 000000000..48762bfd6 --- /dev/null +++ b/template/admin/src/utils/ase.js @@ -0,0 +1,22 @@ +import CryptoJS from 'crypto-js'; +import JSEncrypt from 'jsencrypt'; + +/** + * @word hash256要加密的内容 + * @keyWord String 服务器随机返回的关键字 + * */ +export function aesEncryptHash(word, keyWord = 'XwKsGlMcdPMEhR1B') { + var key = CryptoJS.enc.Utf8.parse(keyWord); + var srcs = CryptoJS.enc.Utf8.parse(word); + var encrypted = CryptoJS.HmacSHA256(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); + return encrypted.toString(); +} +/** + * @word key加密 + * @keyWord String 服务器随机返回的关键字 + * */ +export function encryptWithKey(password, publicKey) { + const encryptor = new JSEncrypt(); + encryptor.setPublicKey(publicKey); + return encryptor.encrypt(password); +}