【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
+5
View File
@@ -9570,6 +9570,11 @@
"integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=",
"dev": true
},
"jsencrypt": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/jsencrypt/-/jsencrypt-3.1.0.tgz",
"integrity": "sha512-A4fIgyPN38G7wwB5t1Vkpi+w7j/nHKdradl/k9/GQqwAsxJqAJ55j3P5rWO3dvjhzOyWKOmK//WwzPO+o6gW0g=="
},
"jsesc": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz",
+1
View File
@@ -24,6 +24,7 @@
"enquire.js": "^2.1.6",
"js-base64": "^3.6.0",
"js-cookie": "^2.2.0",
"jsencrypt": "^3.0.0-rc.1",
"lodash.get": "^4.4.2",
"lodash.pick": "^4.4.0",
"md5": "^2.2.1",
+15
View File
@@ -71,4 +71,19 @@ export function thirdLogin(token,thirdType) {
'Content-Type': 'application/json;charset=UTF-8'
}
})
}
/**
* 获取RSA公钥
* @returns {*}
*/
export function getRSAPublicKey() {
return axios({
url: `/sys/getRSAPublicKey`,
method: 'get',
timeout: 5000,
headers: {
'Content-Type': 'application/json;charset=UTF-8'
}
})
}
+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)=>{})