2012-02-21 4 views
0

안녕하세요. 사용자의 로그인 시도를 제한하고 .... 사용자가 데이터베이스의 "IsBlocked"열에서 로그인 시도를 초과하면 "예"를 삽입해야합니다.로그인 시도를 제한하는 방법?

코드 작업 중 ... 내 코드에서 오류가 내가 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

이 함께

 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 
     { 
      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

그것은 일했다. ... 고맙다.. –

관련 문제