私はしばらくの間グーグルで行っていますが、私はまだ私の質問への答えを見つけることができません。 です:方法があるかどうか、データベースの価値を比較し、それを比較する...私はそれを説明する方法が本当にわからない... so私はあなたが私のコードのためにこれまでに得たものをあなたに示すだろうと思う。 BTW Imはこのプログラムを作成するためにnetbeanを使い、ODBCデータベース(mircosoftアクセス)を使っています。私もコードでtry catchを使用して、それを表示する方法をidk。ログイン - データベースとユーザー入力を比較する
以下のプログラムは本当に私がそれを望むように動作しません。私は問題を比較しているので、 ありがとうございます。
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)を格納します。 このコードはネガティブではありませんが、深刻な危険があります。 –