(improvement)(login) encrypt password (#1081) (#1116)

This commit is contained in:
zhaodongsheng
2024-06-09 08:16:45 +08:00
committed by GitHub
parent dcb7f21241
commit 5bc88b78a9
15 changed files with 289 additions and 95 deletions

View File

@@ -3,6 +3,7 @@ import { message } from 'antd';
import numeral from 'numeral';
import copy from 'copy-to-clipboard';
import { isString } from 'lodash';
import CryptoJS from 'crypto-js';
/* eslint no-useless-escape:0 */
const reg =
@@ -470,3 +471,15 @@ export const objToArray = (_obj: ObjToArrayParams, keyType: string = 'string') =
};
});
};
export function encryptPassword(password: string, username: string) {
if (!password) {
return password;
}
// TODO This key should be stored in a secure place
const key = CryptoJS.enc.Utf8.parse('supersonic@2024');
const srcs = CryptoJS.enc.Utf8.parse(password);
const encrypted = CryptoJS.AES.encrypt(srcs, key, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7});
return encrypted.toString();
};