以下の関数クラスの改善案はありますか?
わかりました ここで、登録メンバーのログインを行うにはどうすればよいですか
HttpCookie LoginInfo = new HttpCookie("LoginInfo");
LoginInfo.Values["UserName"] = srUserName;
LoginInfo.Values["Password"] = srPassword;
LoginInfo.Values["selectedLanguage"] = srSelectedLanguage;
Response.Cookies.Add(LoginInfo);
ここで、訪問者がログインしているかどうかを確認する方法
public static void controlOfLoginStatus()
{
string srQuery = "";
string srUserName = "";
string srPassword = "";
string srLang = "";
if (HttpContext.Current.Session["UserId"] == null)
{
if (HttpContext.Current.Request.Cookies["LoginInfo"] != null)
{
try
{
srUserName = HttpContext.Current.Request.Cookies["LoginInfo"]["UserName"].ToString();
srPassword = HttpContext.Current.Request.Cookies["LoginInfo"]["Password"].ToString();
srLang = HttpContext.Current.Request.Cookies["LoginInfo"]["selectedLanguage"].ToString();
}
catch
{
}
}
string srUserIdTemp = csPublicFunctions.ReturnUserIdUsernamePassword(srUserName, srPassword);
if (srUserIdTemp == "0")
{
HttpContext.Current.Session.Clear();
HttpContext.Current.Session.Abandon();
HttpContext.Current.Response.Redirect("Login");
}
else
{
csPublicFunctions.insertIntoOnlineUsers(srUserIdTemp, HttpContext.Current.Session.SessionID);
HttpContext.Current.Session["UserId"] = srUserIdTemp;
if (HttpContext.Current.Session["lang"] == null)
HttpContext.Current.Session["lang"] = srLang;
}
}
srQuery = "SELECT UserId " +
" FROM BannedUsers" +
" WHERE UserId = " + HttpContext.Current.Session["UserId"].ToString();
using (DataTable dtTemp = DbConnection.db_Select_DataTable(srQuery))
{
if (dtTemp.Rows.Count > 0)
{
HttpContext.Current.Response.Redirect("exit.aspx");
}
}
}
ログアウト方法はこちら
public static void exitLogout()
{
string srQuery = "delete from OnlineUsers where UserId=" + HttpContext.Current.Session["UserId"].ToString();
DbConnection.db_Update_Delete_Query(srQuery);
try
{
HttpContext.Current.Session["UserId"] = "0";
HttpContext.Current.Session.Clear();
HttpContext.Current.Session.Abandon();
}
catch
{
}
try
{
HttpCookie LoginInfo = new HttpCookie("LoginInfo");
LoginInfo.Values["UserName"] = "21412zxcvzxc343245243vvc";
LoginInfo.Values["Password"] = "21412zxcvzxc343245243vvc";
LoginInfo.Values["selectedLanguage"] = "en";
HttpContext.Current.Response.Cookies.Add(LoginInfo);
}
catch
{
}
}
csPublicFunctions.ReturnUserIdUsernamePassword
パラメータ化されたクエリを使用するため、SQL インジェクションのリスクはありません