userName 1 anno fa
parent
commit
7340c0f286

+ 1 - 1
xingyun-api/src/main/resources/application.yml

@@ -1,6 +1,6 @@
1 1
 server:
2 2
   #端口
3
-  port: 8080
3
+  port: 8200
4 4
 spring:
5 5
   application:
6 6
     name: @project.artifactId@

+ 3 - 1
xingyun-template/src/main/java/com/lframework/xingyun/template/inner/controller/AuthController.java

@@ -55,6 +55,7 @@ import com.lframework.xingyun.template.inner.service.system.SysMenuService;
55 55
 import com.lframework.xingyun.template.inner.service.system.SysUserDeptService;
56 56
 import com.lframework.xingyun.template.inner.service.system.SysUserRoleService;
57 57
 import com.lframework.xingyun.template.inner.service.system.SysUserService;
58
+import com.lframework.xingyun.template.inner.sign.util.SecretUtil;
58 59
 import com.lframework.xingyun.template.inner.vo.system.user.LoginVo;
59 60
 import io.swagger.annotations.Api;
60 61
 import io.swagger.annotations.ApiImplicitParam;
@@ -173,7 +174,8 @@ public class AuthController extends DefaultBaseController {
173 174
   public InvokeResult<LoginBo> login(@Valid LoginVo vo) {
174 175
 
175 176
     String username = vo.getUsername();
176
-    String password = vo.getPassword();
177
+    String jmpassword = vo.getPassword();
178
+   String password= SecretUtil.AesDecrypt(jmpassword);
177 179
     String tenantId = null;
178 180
     if (TenantUtil.enableTenant()) {
179 181
       String[] tmpArr = username.split("@");

+ 9 - 5
xingyun-template/src/main/java/com/lframework/xingyun/template/inner/controller/UserCenterController.java

@@ -24,6 +24,7 @@ import com.lframework.starter.web.resp.InvokeResultBuilder;
24 24
 import com.lframework.starter.web.common.utils.ApplicationUtil;
25 25
 import com.lframework.starter.web.common.security.AbstractUserDetails;
26 26
 import com.lframework.starter.web.common.security.SecurityUtil;
27
+import com.lframework.xingyun.template.inner.sign.util.SecretUtil;
27 28
 import io.swagger.annotations.Api;
28 29
 import io.swagger.annotations.ApiImplicitParam;
29 30
 import io.swagger.annotations.ApiImplicitParams;
@@ -86,8 +87,10 @@ public class UserCenterController extends DefaultBaseController {
86 87
       @NotBlank(message = "新密码不能为空!") String newPsw,
87 88
       @NotBlank(message = "确认密码不能为空!") String confirmPsw) {
88 89
 
90
+    String jmoldPsw= SecretUtil.AesDecrypt(oldPsw);
91
+
89 92
     AbstractUserDetails user = getCurrentUser();
90
-    if (!encoderWrapper.getEncoder().matches(oldPsw, user.getPassword())) {
93
+    if (!encoderWrapper.getEncoder().matches(jmoldPsw, user.getPassword())) {
91 94
       throw new InputErrorException("旧密码不正确,请重新输入!");
92 95
     }
93 96
 
@@ -95,11 +98,12 @@ public class UserCenterController extends DefaultBaseController {
95 98
       throw new InputErrorException("两次密码输入不一致,请检查!");
96 99
     }
97 100
 
98
-    if (!RegUtil.isMatch(PatternPool.PATTERN_PASSWORD, newPsw)) {
99
-      throw new InputErrorException("密码格式不正确,请检查!");
100
-    }
101
+//    if (!RegUtil.isMatch(PatternPool.PATTERN_PASSWORD, newPsw)) {
102
+//      throw new InputErrorException("密码格式不正确,请检查!");
103
+//    }
104
+    String jmnewPsw= SecretUtil.AesDecrypt(newPsw);
101 105
 
102
-    sysUserService.updatePassword(user.getId(), newPsw);
106
+    sysUserService.updatePassword(user.getId(), jmnewPsw);
103 107
 
104 108
     //修改密码后,退出登录状态
105 109
     SecurityUtil.logout();

+ 116 - 0
xingyun-template/src/main/java/com/lframework/xingyun/template/inner/sign/util/SecretUtil.java

@@ -0,0 +1,116 @@
1
+package com.lframework.xingyun.template.inner.sign.util;
2
+
3
+import com.aliyuncs.utils.IOUtils;
4
+import org.springframework.util.DigestUtils;
5
+
6
+import javax.crypto.Cipher;
7
+import javax.crypto.SecretKey;
8
+import javax.crypto.spec.SecretKeySpec;
9
+import java.io.ByteArrayInputStream;
10
+import java.io.IOException;
11
+import java.io.InputStream;
12
+import java.security.MessageDigest;
13
+import java.security.NoSuchAlgorithmException;
14
+import java.util.Base64;
15
+
16
+public class SecretUtil {
17
+    public static String MD5(String decrypt) {
18
+        return DigestUtils.md5DigestAsHex(decrypt.getBytes());
19
+    }
20
+
21
+    public static String SHA1(String decrypt) {
22
+        try {
23
+            MessageDigest digest = MessageDigest.getInstance("SHA-1");
24
+            digest.update(decrypt.getBytes());
25
+            byte messageDigest[] = digest.digest();
26
+            // Create Hex String
27
+            StringBuffer hexString = new StringBuffer();
28
+            // 字节数组转换为 十六进制 数
29
+            for (int i = 0; i < messageDigest.length; i++) {
30
+                String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);
31
+                if (shaHex.length() < 2) {
32
+                    hexString.append(0);
33
+                }
34
+                hexString.append(shaHex);
35
+            }
36
+            return hexString.toString();
37
+
38
+        } catch (NoSuchAlgorithmException e) {
39
+            e.printStackTrace();
40
+        }
41
+        return "";
42
+    }
43
+
44
+    public static String SHA256(String s) {
45
+        InputStream fis = new ByteArrayInputStream(s.getBytes());
46
+        return SHA256(fis);
47
+    }
48
+
49
+    public static String SHA256(InputStream inputStream) {
50
+        byte buffer[] = new byte[1024 * 10];
51
+        MessageDigest md5 = null;
52
+        try {
53
+            md5 = MessageDigest.getInstance("SHA-256");
54
+            for (int numRead = 0; (numRead = inputStream.read(buffer)) > 0; ) {
55
+                md5.update(buffer, 0, numRead);
56
+            }
57
+            byte[] digest = md5.digest();
58
+            StringBuffer strHexString = new StringBuffer();
59
+            for (int i = 0; i < digest.length; i++) {
60
+                String hex = Integer.toHexString(0xff & digest[i]);
61
+                if (hex.length() == 1) {
62
+                    strHexString.append('0');
63
+                }
64
+                strHexString.append(hex);
65
+            }
66
+            return strHexString.toString();
67
+        } catch (NoSuchAlgorithmException | IOException e) {
68
+            e.printStackTrace();
69
+        } finally {
70
+            IOUtils.closeQuietly(inputStream);
71
+        }
72
+        return null;
73
+    }
74
+
75
+
76
+    private static String AES_KEY = "j8z&j*a$t{w#k}e@";
77
+    private static String AES_ECB = "AES/ECB/PKCS5Padding";
78
+
79
+    /**
80
+     * 使用AES加密原始字符串.
81
+     *
82
+     * @param input 原始输入字符串
83
+     */
84
+    public static String AesEncrypt(String input) {
85
+        try {
86
+            SecretKey secretKey = new SecretKeySpec(AES_KEY.getBytes(), "AES");
87
+            Cipher cipher = Cipher.getInstance(AES_ECB);
88
+            cipher.init(Cipher.ENCRYPT_MODE, secretKey);
89
+            byte[] result = cipher.doFinal(input.getBytes("utf-8"));
90
+            return Base64.getEncoder().encodeToString(result);
91
+        } catch (Exception e) {
92
+            e.printStackTrace();
93
+        }
94
+        return "";
95
+    }
96
+
97
+    /**
98
+     * 使用AES解密原始字符串.
99
+     *
100
+     * @param input 原始输入字符串
101
+     */
102
+    public static String AesDecrypt(String input) {
103
+        try {
104
+            SecretKey secretKey = new SecretKeySpec(AES_KEY.getBytes(), "AES");
105
+            Cipher cipher = Cipher.getInstance(AES_ECB);
106
+            cipher.init(Cipher.DECRYPT_MODE, secretKey);
107
+            byte[] result = cipher.doFinal(Base64.getDecoder().decode(input));
108
+            return new String(result, "utf-8");
109
+        } catch (Exception e) {
110
+            e.printStackTrace();
111
+        }
112
+        return "";
113
+    }
114
+
115
+
116
+}