document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. public partial class Login : System.Web.UI.Page
  2. {
  3.     private string connStr = WebConfigurationManager.ConnectionStrings["db"].ConnectionString;
  4.  
  5.     protected void Page_Load(object sender, EventArgs e)
  6.     {
  7.     }
  8.     protected void btnLogin_Click(object sender, EventArgs e)
  9.     {
  10.         string userid = txtUserId.Text;
  11.         string password = txtPassword.Text;
  12.         DataTable dt = new DataTable();
  13.  
  14.         try
  15.         {
  16.             using (SqlConnection conn = new SqlConnection(connStr))
  17.             {
  18.                 using (SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM User WHERE [UserID]=@UserID AND [UserPassword]=@UserPassword", conn))
  19.                 {
  20.                     da.SelectCommand.Parameters.AddWithValue("@UserID", userid);
  21.                     da.SelectCommand.Parameters.AddWithValue("@UserPassword", password);
  22.                     da.Fill(dt);
  23.                 }
  24.             }
  25.  
  26.             if (dt.Rows.Count > 0)
  27.             {
  28.                 Session["AccountID"] = userid;
  29.                 Response.Redirect("Default.aspx");
  30.             }
  31.             else
  32.             {
  33.                 //利用Application來記錄帳號被輸入錯誤了多少次
  34.                 if (Application[userid] == null)
  35.                     Application[userid] = 1;
  36.                 else
  37.                     Application[userid] = Convert.ToInt32(Application[userid]) + 1;
  38.  
  39.                 //判斷該帳號輸入錯誤的次數到一定次數,導向其他網頁
  40.                 if (Convert.ToInt32(Application[userid]) >= 10)
  41.                     Response.Redirect("UnLock.aspx");
  42.  
  43.             }
  44.         }
  45.         catch (Exception)
  46.         {
  47.         }
  48.     }
  49. }
');