나는 잠시 동안 인터넷 검색을하고 아직도 내 질문에 대한 답변을 찾을 수 없습니다. : 나는 방법이나 방법이 있는지 알고 싶습니다. 데이터베이스의 가치를 확인한 다음 비교해보십시오 ... 설명하는 방법을 잘 모르겠습니다. 내 코드에 대해 지금까지 무엇을 얻었는지 보여 드리겠습니다. BTW 임 netbean을 사용 하여이 프로그램과 메신저 ODBC 데이터베이스 (mircosoft 액세스)를 사용합니다. 또한 코드에 try catch를 사용하여 보여 주지만 어떻게 만드는지 ..로그인 - 데이터베이스와 사용자 입력 비교
아래의 프로그램은 내가 원하는 방식으로 작동하지 않습니다. 비교할 때 문제가 있기 때문에. 미리 감사드립니다.
if(request.getParameter("username")!=null && request.getParameter("username") !=""
&& request.getParameter("password")!=null && request.getParameter("password")!=""){
String user = request.getParameter("username").toString();
String pass = request.getParameter("password").toString();
String check = "SELECT AccountType FROM Testing WHERE Username='"+user+"' AND Password ='"+pass+"'";
rs = stmt.executeQuery(check);
String info = rs.getString(check); // trying to get the AccountType and store it into a string
while(rs.next()){
if(info != null && info !=""){ //checks to see if the account exist in the database
if(info.equals("Admin")){ //checks to see if AccountType is "Admin"
response.sendRedirect("AdminConsole.jsp");
}else
response.sendRedirect("UserConsole.jsp");
}else
response.sendRedirect("ErrorPage2.jsp");
}
}else
response.sendRedirect("ErrorPage.jsp");
connection.close();
}
SQL 인젝션 취약점이 있습니다. – SLaks
암호를 일반 텍스트로 저장하면 안됩니다. 위의 문제를 해결하기 위해 – SLaks
; - 매개 변수가있는 쿼리를 사용하여 SQL 삽입 방지 - 비교할 암호의 해시 (예 : MD5)를 저장합니다. 음수가 아니며이 코드는 매우 위험합니다. –