2011-06-14 181 views
-2

此方法应比较用户给出的登录名/密码存储在数据库中的登录名/密码,但此方法返回始终为false指令大小不起作用!方法检查登录名和密码

public String loginPasswordCheck() { 
    Connectionx cx = new Connectionx(); 
    Connection con = (Connection) cx.Connxion("com.mysql.jdbc.Driver","jdbc:mysql://localhost/kpidb", "root", "root"); 
    String log; 
    String pwd; 
    String checkaccess = "success"; 
    int profil_user; 
    HashMap<String, String> mapLoginPWD = new HashMap<String, String>(); 
    HashMap<String, HashMap<String, String>> mapID_LoginPWD = new HashMap<String, HashMap<String, String>>(); 
    HashMap<String, String> temp = new HashMap<String, String>(); 
    String sqlLogin; 
    sqlLogin = "select PROFIL_USER_ID,login ,password from profil_user;"; 

    try { 

     st = (PreparedStatement) con.prepareStatement(sqlLogin); 
     ResultSet rs1 = st.executeQuery(); 

     while (rs1.next()) { 
      profil_user = rs1.getInt("PROFIL_USER_ID"); 
      profil_user_id = String.valueOf(profil_user); 

      log = rs1.getString("login"); 
      pwd = rs1.getString("password"); 
      mapLoginPWD.put(log, pwd); 
      mapID_LoginPWD.put(profil_user_id, mapLoginPWD); 
      Iterator iteratorkeymaploginPWD = mapID_LoginPWD.keySet().iterator(); 

      while (iteratorkeymaploginPWD.hasNext()) { 

       String myKeylog = (String) iteratorkeymaploginPWD.next(); 
       temp = mapID_LoginPWD.get(myKeylog); 

       Iterator iteratortemp = temp.keySet().iterator(); 
       while (iteratortemp.hasNext()) { 

        String keyTemplog = (String) iteratortemp.next(); 
        String valueTemppwd = temp.get(keyTemplog); 
        temp.clear(); 
        mapID_LoginPWD.clear(); 
        boolean bool = true; 
        if (!(this.login.equalsIgnoreCase(keyTemplog)) && !(this.password.equalsIgnoreCase(valueTemppwd)) && (bool)) { 

         bool = false; 
         checkaccess = "fail"; 
        } else { 
         checkaccess = "success"; 
         break; 
        } 
       } 
      } 
     } 
    } 
    catch (SQLException e) { 
     e.printStackTrace(); 
    } 
    return checkaccess; 
} 
+0

这应该真的,如果你的两个案件的成功和失败,并返回一个布尔当你在方法 – Grammin 2011-06-14 15:26:18

+0

@Grammin的末尾得知checkaccess状态时,你应该做正确的返回,当我在条件中添加了逆向checkaccess时,如果错误缺少返回语句出现r,这就是我为什么这么做的原因 – rym 2011-06-14 15:39:07

+0

-1:您是否尝试过一步步调试,找出哪一行不能按预期工作? – 2011-06-14 16:09:27

回答

0

的逻辑是非常难走,但我相信

boolean bool = true; 

需求来之前

while (iteratortemp.hasNext()) { 
+0

我已经解决了我的问题:) – rym 2011-06-15 08:15:14

相关问题