Эх сурвалжийг харах

feat: 登录密码去掉md5处理

weijianghai 2 жил өмнө
parent
commit
c888b742f9

+ 7 - 10
src/main/java/com/nokia/hb/utils/DbUtil.java

@@ -5,7 +5,6 @@ import com.nokia.hb.Pojo.RetData;
 import com.nokia.hb.Pojo.TreeNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.util.DigestUtils;
 import org.springframework.util.StringUtils;
 
 import javax.servlet.http.HttpSession;
@@ -576,26 +575,24 @@ public class DbUtil {
     // }
 
     public static Object userLogin(String username, String password, HttpSession session) {
-        // 计算密码md5
-        String passwordMd5 = DigestUtils.md5DigestAsHex(password.getBytes());
-        log.debug("username: {}, password: {}, passwordMd5: {}", username, password, passwordMd5);
+        log.debug("username: {}, password: {}", username, password);
         // 查询用户信息
         String sql = "select * from pm_parse.user where username='" + username + "'";
-        PreparedStatement psmt = null;
+        PreparedStatement psmt;
         try {
             psmt = conn.prepareStatement(sql);
             psmt.setQueryTimeout(60 * 10);
             ResultSet rs = psmt.executeQuery();
             // 没有查到数据
             if (!rs.next()) {
-                return 0;
+                return "用户名或密码错误!";
             }
 
             String passwordStore = rs.getString("password");
             log.debug("passwordStore: {}", passwordStore);
             // 密码错误
-            if (!passwordMd5.equals(passwordStore)) {
-                return 0;
+            if (!password.equals(passwordStore)) {
+                return "用户名或密码错误!";
             }
 
             // 查询地区权限
@@ -614,10 +611,10 @@ public class DbUtil {
             session.setMaxInactiveInterval(30 * 60);
             session.setAttribute("username", username);
             session.setAttribute("areas", map);
-            return 1;
+            return null;
         } catch (SQLException e) {
             e.printStackTrace();
-            return 0;
+            return "数据库异常!";
         }
     }
 

+ 8 - 9
src/main/resources/templates/login.html

@@ -57,18 +57,17 @@
                     "password": password,
                 },
                 success: function (r) {
-                    console.log(`response: ${JSON.stringify(r)}`)
-
-                    if (r === 1) {
-                        layer.msg('登录成功');
-                        window.location.href = '/template'
-                        return true;
-                    } else {
-                        layer.msg('用户名或密码错误!');
+                    if (r) {
+                        alert(r)
+                        return false
                     }
+
+                    layer.msg('登录成功');
+                    window.location.href = '/template'
+                    return true
                 }
             });
-            return false;
+            return false
         });
     });
 </script>