2012-02-21 9 views
0

こんにちは私はユーザーのログイン試行を制限しなければなりません....そして、ユーザーがデータベースの "IsBlocked"列のログイン試行を超過する場合、 "yes"を挿入してくださいログイン試行を制限する方法は?

私はコード作業中です...私のコード内のエラーは、私がfailedattemptsをicrementカントいただきました!私はここで私は

  SqlConnection con2 = new SqlConnection(connstring); 
      string cmd1 = "select Emp_IsBlocked from dbo.PTS_Employee where Emp_Username='" + EmployeeName + "' and Emp_Password='" + Password + "'"; 
      SqlCommand mycomm2 = new SqlCommand(cmd1, con2); 
      con2.Open(); 
      Object Blocked = mycomm2.ExecuteScalar(); 
      con2.Close(); 
      if (Blocked != null) 
      { 
       if (Blocked.ToString() == "") 
       { 
        Response.Redirect("~/Transactions.aspx"); 
       } 
       else 
       { 
        lblError.Text = "You are Temporarily Blocked for Exceeding Max Number of Login Attempts"; 
       } 
      } 

      else 
      { 
       _failedAttempts++; 
       //lblError.Text = ("Fail. " + (3 - _failedAttempts)); 

       if (_failedAttempts == 3) 
       { 
        SqlConnection con1 = new SqlConnection(connstring); 
        SqlCommand mycomm1 = new SqlCommand("SP_IsBlocked", con1); 
        mycomm1.CommandType = CommandType.StoredProcedure; 
        con1.Open(); 
        mycomm1.Parameters.Add("@IsBlocked", SqlDbType.VarChar).Value = "Yes"; 
        mycomm1.ExecuteNonQuery(); 
        con1.Close(); 
        lblError.Text = "You are Temporarily Blocked for Exceeding Max Number of Login Attempts"; 
       } 


      } 

に取り組んでいたコードは、任意の上記のコードまたはどのようにそれを行うためにいただきました!間違ったと言うことができているかわからない..... ....?

+0

ないデータベースを使用して最善の解決策を試してみてください... – Madhu

+0

あなたのコードを文字列cmd1 = "Emp_Username = '" + EmployeeName + "'およびEmp_Password = '" + Password + "'";のdbo.PTS_EmployeeからEmp_IsBlockedを選択します。あなたのコードで何が起こっているかを見るためにデバッガを付けましたか?あなたのコードに#loginの試行回数が保存されていません。 – Peter

答えて

1

uは、これに代えてキャッシュを実装する必要があるかもしれません...。これにより

 else 
     { 
      _failedAttempts++; 
      //lblError.Text = ("Fail. " + (3 - _failedAttempts)); 

      if (_failedAttempts == 3) 
      { 
       SqlConnection con1 = new SqlConnection(connstring); 
       SqlCommand mycomm1 = new SqlCommand("SP_IsBlocked", con1); 
       mycomm1.CommandType = CommandType.StoredProcedure; 
       con1.Open(); 
       mycomm1.Parameters.Add("@IsBlocked", SqlDbType.VarChar).Value = "Yes"; 
       mycomm1.ExecuteNonQuery(); 
       con1.Close(); 
       lblError.Text = "You are Temporarily Blocked for Exceeding Max Number of Login Attempts"; 
      } 


     } 

のごelse文を交換し、

 else 
     { 
      object FailedLoginCounter = this.Page.Cache["UserKey_" + this.txtPwd.Text]; 
      if (FailedLoginCounter == null) 
      { 
       FailedLoginCounter = 0; 
      } 
      this.Page.Cache["UserKey_" + this.txtPwd.Text] = (int)FailedLoginCounter + 1; 
      if (((int)this.Page.Cache["UserKey_" + this.txtPwd.Text]) == 3) 
      { 
       SqlConnection con1 = new SqlConnection(connstring); 
       SqlCommand mycomm1 = new SqlCommand("SP_IsBlocked", con1); 
       mycomm1.CommandType = CommandType.StoredProcedure; 
       con1.Open(); 
       mycomm1.Parameters.Add("@IsBlocked", SqlDbType.VarChar).Value = "Yes"; 
       mycomm1.ExecuteNonQuery(); 
       con1.Close(); 
       lblError.Text = "You are Temporarily Blocked for Exceeding Max Number of Login Attempts"; 
      } 
     } 
+0

ohk私はこれを試してみましょう.... –

+0

それは働いて....ありがとう.. –

関連する問題