Commit 72bc7f8fb4424e654eff79f5ba7c5181da0a5285

Authored by zhangdaihao
1 parent 744ace0c

密码加密解码报错处理

ant-design-vue-jeecg/src/store/mutation-types.js
... ... @@ -13,6 +13,7 @@ export const USER_NAME = 'Login_Username'
13 13 export const USER_INFO = 'Login_Userinfo'
14 14 export const USER_AUTH = 'LOGIN_USER_BUTTON_AUTH'
15 15 export const SYS_BUTTON_AUTH = 'SYS_BUTTON_AUTH'
  16 +export const ENCRYPTED_STRING = 'ENCRYPTED_STRING'
16 17  
17 18 export const CONTENT_WIDTH_TYPE = {
18 19 Fluid: 'Fluid',
... ...
ant-design-vue-jeecg/src/utils/encryption/aesEncrypt.js
  1 +import { getAction } from '@/api/manage'
  2 +import { ENCRYPTED_STRING } from "@/store/mutation-types"
  3 +import Vue from 'vue'
1 4  
  5 +/**
  6 + * 获取加密字符串,并对结果进行缓存
  7 + */
  8 +export function getEncryptedString() {
  9 + return getAction("/sys/getEncryptedString",{}).then((res)=>{
  10 + let encryptedString = {};
  11 + encryptedString.key = res.result.key;
  12 + encryptedString.iv = res.result.iv;
  13 + Vue.ls.set(ENCRYPTED_STRING, encryptedString, 7 * 24 * 60 * 60 * 1000);
  14 + return encryptedString;
  15 + });
  16 +}
2 17  
3 18 /**
4 19 * AES加密 :字符串 key iv 返回base64
... ...
ant-design-vue-jeecg/src/views/user/Login.vue
... ... @@ -171,12 +171,11 @@
171 171 import { mapActions } from "vuex"
172 172 import { timeFix } from "@/utils/util"
173 173 import Vue from 'vue'
174   - import { ACCESS_TOKEN } from "@/store/mutation-types"
  174 + import { ACCESS_TOKEN ,ENCRYPTED_STRING} from "@/store/mutation-types"
175 175 import JGraphicCode from '@/components/jeecg/JGraphicCode'
176 176 import { putAction } from '@/api/manage'
177 177 import { postAction } from '@/api/manage'
178   - import { getAction} from '@/api/manage'
179   - import { encryption } from '@/utils/encryption/aesEncrypt'
  178 + import { encryption , getEncryptedString } from '@/utils/encryption/aesEncrypt'
180 179  
181 180 export default {
182 181 components: {
... ... @@ -192,6 +191,10 @@
192 191 requiredTwoStepCaptcha: false,
193 192 stepCaptchaVisible: false,
194 193 form: this.$form.createForm(this),
  194 + encryptedString:{
  195 + key:"",
  196 + iv:"",
  197 + },
195 198 state: {
196 199 time: 60,
197 200 smsSendBtn: false,
... ... @@ -224,6 +227,7 @@
224 227 created () {
225 228 Vue.ls.remove(ACCESS_TOKEN)
226 229 this.getRouterData();
  230 + this.getEncrypte();
227 231 // update-begin- --- author:scott ------ date:20190225 ---- for:暂时注释,未实现登录验证码功能
228 232 // this.$http.get('/auth/2step-code')
229 233 // .then(res => {
... ... @@ -256,23 +260,23 @@
256 260 let loginParams = {
257 261 remember_me: that.formLogin.rememberMe
258 262 };
259   -
  263 + that.loginBtn = true;
260 264 // 使用账户密码登陆
261 265 if (that.customActiveKey === 'tab1') {
262 266 that.form.validateFields([ 'username', 'password','inputCode' ], { force: true }, (err, values) => {
263 267 if (!err) {
264   - getAction("/sys/getEncryptedString",{}).then((res)=>{
265   - loginParams.username = values.username
266   - //loginParams.password = md5(values.password)
267   - loginParams.password = encryption(values.password,res.result.key,res.result.iv)
268   - that.Login(loginParams).then((res) => {
269   - this.departConfirm(res)
270   - }).catch((err) => {
271   - that.requestFailed(err);
272   - })
  268 + loginParams.username = values.username
  269 + //loginParams.password = md5(values.password)
  270 + loginParams.password = encryption(values.password,that.encryptedString.key,that.encryptedString.iv).replace(/\+/g,"%2B");
  271 + that.Login(loginParams).then((res) => {
  272 + this.departConfirm(res)
273 273 }).catch((err) => {
274 274 that.requestFailed(err);
275 275 });
  276 +
  277 +
  278 + }else {
  279 + that.loginBtn = false;
276 280 }
277 281 })
278 282 // 使用手机号登陆
... ... @@ -453,6 +457,17 @@
453 457 });
454 458 })
455 459 },
  460 + //获取密码加密规则
  461 + getEncrypte(){
  462 + var encryptedString = Vue.ls.get(ENCRYPTED_STRING);
  463 + if(encryptedString == null){
  464 + getEncryptedString().then((data) => {
  465 + this.encryptedString = data
  466 + });
  467 + }else{
  468 + this.encryptedString = encryptedString;
  469 + }
  470 + },
456 471 }
457 472 }
458 473 </script>
... ...
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/config/RedisConfig.java
... ... @@ -86,7 +86,7 @@ public class RedisConfig extends CachingConfigurerSupport {
86 86 RedisCacheWriter writer = RedisCacheWriter.lockingRedisCacheWriter(factory);
87 87 // 创建默认缓存配置对象
88 88 /* 默认配置,设置缓存有效期 1小时*/
89   - RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(1)).disableCachingNullValues();
  89 + RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(1));
90 90 /* 配置test的超时时间为120s*/
91 91 RedisCacheManager cacheManager = RedisCacheManager.builder(RedisCacheWriter.lockingRedisCacheWriter(lettuceConnectionFactory)).cacheDefaults(defaultCacheConfig)
92 92 .withInitialCacheConfigurations(singletonMap("test", RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(120)).disableCachingNullValues()))
... ...
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/LoginController.java
... ... @@ -68,7 +68,7 @@ public class LoginController {
68 68 String username = sysLoginModel.getUsername();
69 69 String password = sysLoginModel.getPassword();
70 70 //步骤1:TODO 前端密码加密,后端进行密码解密,防止传输密码篡改等问题,不配就直接提示密码错误,并记录日志后期进行统计分析是否锁定
71   - password = AesEncryptUtil.desEncrypt(sysLoginModel.getPassword()).trim();//密码解密
  71 + password = AesEncryptUtil.desEncrypt(sysLoginModel.getPassword().replaceAll("%2B", "\\+")).trim();//密码解密
72 72 //1. 校验用户是否有效
73 73 SysUser sysUser = sysUserService.getUserByName(username);
74 74 result = sysUserService.checkUserIsEffective(sysUser);
... ... @@ -249,7 +249,7 @@ public class LoginController {
249 249  
250 250 } catch (ClientException e) {
251 251 e.printStackTrace();
252   - result.error500(" 短信接口异常,请联系管理员!");
  252 + result.error500(" 短信接口未配置,请联系管理员!");
253 253 return result;
254 254 }
255 255 return result;
... ...