登录加密

xuhongjie
严飞永 1 month ago
parent 1daf3eace4
commit f0d18fcc62

@ -43,7 +43,7 @@
"autofit.js": "^3.2.2",
"axios": "0.28.1",
"clipboard": "2.0.8",
"core-js": "3.37.1",
"core-js": "^3.42.0",
"docx-preview": "^0.3.5",
"echarts": "^5.4.0",
"element-ui": "^2.15.13",
@ -57,10 +57,12 @@
"mars2d": "^3.3.1",
"mars2d-esri": "^3.3.1",
"moment": "^2.30.1",
"node-forge": "^1.3.1",
"nprogress": "0.2.0",
"quill": "2.0.2",
"regenerator-runtime": "^0.14.1",
"screenfull": "5.0.2",
"sortablejs": "1.10.2",
"sortablejs": "^1.10.2",
"splitpanes": "2.4.1",
"vue": "2.6.12",
"vue-count-to": "1.0.13",

@ -46,7 +46,7 @@
style="width:100%;background: #2B62F1;" @click.native.prevent="handleEnterpriseLogin">
<span>企业统一身份认证登录</span>
</el-button>
</el-form-item>
<div style="font-size: 0.88rem;color: #333;">主办单位苏州工业园区经济发展委员会</div>
</el-form>
@ -61,6 +61,7 @@
import { getCodeImg } from '@/api/login'
import Cookies from 'js-cookie'
import { encrypt, decrypt } from '@/utils/jsencrypt'
import forge from 'node-forge'
export default {
name: 'Login',
@ -86,31 +87,33 @@ export default {
code: [{ required: true, trigger: 'change', message: '请输入验证码' }]
},
loading: false,
//
captchaEnabled: true,
//
register: false,
redirect: undefined
redirect: undefined,
a1: `MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl8bS1kYTiMhIS5MZU253bc0ukaxrA1lfCziABFxQrC2c09tMrQGjuH6V1x2ofNBMGhOD9uWN/qkAQy/HwOe/NKUqCw6N0ov6guSrqMDW/BdZ3Bl0rmM1/95jTC1xffFFvej7xWNffIbaPI+bJ4WLX9NViNi9HmT0BRNzJ4d2R86LPPCa+bxLaPjsh2R2tBkbLkUot9769aJaPPiwPCZHMkuQenjHSmpWL0okleqMH8EGX7j6A5A/4IUXPMNKMMzkiSRpsIJ65GJmDAbnR3ZXRfC8MzVBBJB6zr5N0F4N9xZfF+JS/Yx726tCu+rA6GDCyTxtQ/wnKpPdwFP5nUWCWQIDAQAB`
}
},
watch: {
$route(route) {
this.redirect = route.query && route.query.redirect
$route: {
handler: function (route) {
this.redirect = route.query && route.query.redirect;
},
immediate: true
},
activeName(newVal) {
if (newVal === 'first') {
this.loginForm.loginRole = 2;
this.loginForm.loginRole = 2
} else if (newVal === 'second') {
this.loginForm.loginRole = 1;
this.loginForm.loginRole = 1
}
}
},
computed: {
showGovernmentLoginButton() {
return this.activeName === 'second';
return this.activeName === 'second'
},
showEnterpriseLoginButton() {
return this.activeName === 'first';
return this.activeName === 'first'
}
},
created() {
@ -119,15 +122,13 @@ export default {
},
methods: {
getCode() {
getCodeImg().then((res) => {
this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
getCodeImg().then(res => {
this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
if (this.captchaEnabled) {
this.codeUrl = `data:image/gif;base64,${res.img}`
this.loginForm.uuid = res.uuid
this.codeUrl = "data:image/gif;base64," + res.img;
this.loginForm.uuid = res.uuid;
}
}).catch((error) => {
console.error('获取验证码失败:', error)
})
});
},
getCookie() {
const username = Cookies.get('username')
@ -140,25 +141,47 @@ export default {
}
},
handleLogin() {
this.$refs.loginForm.validate((valid) => {
this.$refs.loginForm.validate(valid => {
if (valid) {
this.loading = true;
if (this.loginForm.rememberMe) {
Cookies.set('username', this.loginForm.username, { expires: 30 });
Cookies.set('password', encrypt(this.loginForm.password), { expires: 30 });
Cookies.set("username", this.loginForm.username, { expires: 30 });
Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
} else {
Cookies.remove('username');
Cookies.remove('password');
Cookies.remove("username");
Cookies.remove("password");
Cookies.remove('rememberMe');
}
// 2048 RSA
const lines = [];
lines.push('-----BEGIN PUBLIC KEY-----');
for (let i = 0; i < this.a1.length; i += 64) {
lines.push(this.a1.slice(i, i + 64));
}
lines.push('-----END PUBLIC KEY-----');
lines.join('\n')
const publicKey = forge.pki.publicKeyFromPem(lines.join('\n'));
//
var dataBytes = forge.util.encodeUtf8(this.loginForm.password);
//
var encryptedBytes = publicKey.encrypt(dataBytes, 'RSA-OAEP', {
md: forge.md.sha256.create(),
mgf1: {
md: forge.md.sha1.create()
}
});
// Base64
var encryptedBase64 = forge.util.encode64(encryptedBytes);
//
const loginData = {
username: this.loginForm.username,
password: this.loginForm.password,
password: encryptedBase64,
code: this.loginForm.code,
uuid: this.loginForm.uuid,
loginRole: this.activeName === 'first' ? 2 : 1
loginRole: this.activeName === 'first' ? 2 : 1
};
this.$store.dispatch('Login', loginData)
@ -172,15 +195,15 @@ export default {
}
console.error('登录失败:', error);
});
}
});
},
handleGovernmentLogin() {
//
window.location.href = 'https://qyt.sipac.gov.cn/';
window.location.href = 'https://qyt.sipac.gov.cn/'
},
handleEnterpriseLogin() {
//
//
// window.location.href = 'https://example.com/enterprise-login';
}
}

Loading…
Cancel
Save