2011-06-14 4 views
-2

이 방법은 사용자가 지정한 로그인/패스워드를 데이터베이스에 저장된 로그인/패스워드와 비교해야만한다. 그러나이 방법은 항상 braek이 작동하지 않는 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

이 정말 부울을 반환해야합니다 전에

boolean bool = true; 

요구에 올 생각 체크섬 상태를 알았을 때 return을 올바르게 수행해야합니다. – Grammin

+0

@Grammin, 조건에 retrun checkaccess를 추가 한 경우 return 문이 누락되었습니다. r, 그 이유는 내가 그랬어 – rym

+0

-1 :이 단계별 디버깅을 시도하여 예상대로 작동하지 않는 행을 찾으십니까? –

답변

0

논리는 따라하기가 매우 어렵습니다,하지만 난 당신의 이가지 경우 성공하고 실패하고

while (iteratortemp.hasNext()) { 
+0

내 문제를 해결 한 경우 :) – rym

관련 문제