2011-06-14 178 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

相關問題