【add】登录采用RSA加密的模式进行处理用户名和密码

This commit is contained in:
mzc5649
2021-04-16 13:20:42 +08:00
parent c587cc32d5
commit 00faa74f69
4 changed files with 43 additions and 4 deletions
+22 -4
View File
@@ -182,6 +182,9 @@
import { ACCESS_TOKEN ,ENCRYPTED_STRING} from "@/store/mutation-types"
import { putAction,postAction,getAction } from '@/api/manage'
import { USER_INFO } from "@/store/mutation-types"
import {getRSAPublicKey} from '@/api/login.js'
const Base64 = require('js-base64').Base64
import {JSEncrypt} from 'jsencrypt'
export default {
components: {},
@@ -211,6 +214,7 @@
currdatetime:'',
randCodeImage:'',
requestCodeSuccess:false,
rsaPublicKey:''
}
},
created () {
@@ -218,6 +222,7 @@
Vue.ls.remove(ACCESS_TOKEN)
this.getRouterData();
this.handleChangeCheckCode();
},
methods: {
...mapActions(['Login', 'Logout', 'PhoneLogin']),
@@ -236,14 +241,19 @@
that.loginBtn = true;
that.form.validateFields([ 'username', 'password','inputCode', 'rememberMe' ], { force: true }, (err, values) => {
if (!err) {
loginParams.username = values.username
loginParams.password = values.password
loginParams.remember_me = values.rememberMe
loginParams.captcha = that.inputCodeContent
loginParams.checkKey = that.currdatetime
// console.log("登录参数",loginParams)
loginParams.rsaPublicKey = that.rsaPublicKey;
// 新建JSEncrypt对象
let encrypt = new JSEncrypt();
encrypt.setPublicKey(loginParams.rsaPublicKey);
// 公钥加密
loginParams.username = encrypt.encrypt(values.username)
loginParams.password = encrypt.encrypt(values.password)
//登录
that.Login(loginParams).then((res) => {
//登录成功
this.loginSuccess()
}).catch((err) => {
if (err.code === 500) {
@@ -309,6 +319,14 @@
}).catch(()=>{
this.requestCodeSuccess=false
})
this.getPublicKey();
},
//获取RSA公钥
getPublicKey(){
// 获取公钥
getRSAPublicKey().then(res => {
this.rsaPublicKey = res.result
})
},
loginSuccess () {
this.$router.push({ path: "/dashboard/analysis" }).catch((res)=>{})