2014-06-11 4 views
0

좋아, 나는 이것이 꽤 자기 설명 적이며 쉬운 일이라고 생각한다. 그러나 나는 어떤 이유로이 일을 할 수 없습니다.VB.net 로그인 시도 카운터

Partial Class IntroductionPage 'CodeBehind for an ASPX Web page. 
    Public NumberOfAttempts As Integer = 0 
    Protected Sub PinButton_Click(sender As Object, e As System.EventArgs) Handles PinButton.Click 
     NumberOfAttempts = NumberOfAttempts + 1 
     'Query the database for the password, etc (omitted)... 
     If (x = 1 And NumberOfAttempts <= 10) Then 
      ' Then Login the user successfully. (omitted) 
     Else 
      ' The Pin was not found in the DB. We should throw error and make the validation label visible. (omitted) 
     End If 
     If (NumberOfAttempts > 10) Then 
      AttemptsErrorMessage.Visible = True 
     End If 
    End Sub 
End Class 

이 테스트에서 나는 잘못된 비밀번호로 10 회 로그인하려고 시도했지만 레이블이 표시되지 않습니다. 나는 매번 다른 암호를 시도했다. 또한 10 회 시도 후에도 유효한 암호를 시도한 다음 프로그램이 사용자를 성공적으로 로그온했습니다 (첫 번째 if 문의 논리를 기반으로해서는 안됨).

정확히 같은 프로세스를 설명하는 몇 가지 다른 리소스뿐만 아니라이 리소스를 따르려고했습니다. How to count login attempts Visual Basic. 향후 시청자를위한 메모/편집 : 기본적으로 ASPX 웹 페이지의 경우 리소스가 올바르지 않을 수 있습니다. 적어도 나는 그런 식으로 일할 수 없었다. 아래 답변 및 의견을 참조하십시오.

+0

여기서 /는 어떻게 'NumberOfAttempts'가 정의되어 있습니까? 어디에/어떻게'x'가 정의되어 있는가, 어디에서 왔는가? 어떤 부분이 예상대로 작동하지 않는지 확인하기 위해 중단 점을 설정 했습니까? – Plutonix

+0

레이블에 텍스트가 있고 다른 컨트롤 뒤에 숨어 있지 않은지 확인하십시오. – UnhandledExcepSean

+0

이 웹 페이지 또는 Windows 폼입니까? –

답변

3

응용 프로그램이 웹 응용 프로그램입니다, 그래서 카운터의 값이 0이 라인으로 다시 게시 할 때마다 재설정 중입니다 :

Public NumberOfAttempts As Integer = 0 

당신은에 시도의 수를 추적 할 필요가 Session (또는 다른 영구 저장소 메커니즘). 그 수를 증가 (그리고 다시 퍼팅,

Partial Class IntroductionPage 'CodeBehind for an ASPX Web page. 

    Protected Sub PinButton_Click(sender As Object, e As System.EventArgs) Handles PinButton.Click 

     Dim NumberOfAttempts As Integer 

     If Session("NumberOfAttempts") Is Not Nothing Then   
      NumberOfAttempts = CInt(Session("NumberOfAttempts")) 
     End If 

     'Query the database for the password, etc (omitted).. 

     NumberOfAttempts = NumberOfAttempts + 1 
     Session("NumberOfAttempts") = NumberOfAttempts 

     If (x = 1 And NumberOfAttempts <= 10) Then 
      ' Then Login the user successfully. (omitted) 
     Else 
      ' The Pin was not found in the DB. We should throw error and make the validation label visible. (omitted) 
     End If 

     If (NumberOfAttempts > 10) Then 
      AttemptsErrorMessage.Visible = True 
     End If 
    End Sub 
End Class 

위의 코드를 세션에 값이 있는지 확인하고 그 값을 받고에서 중요한 부분은 (는 기본적으로 0입니다) :이 같은 시도 사용자가 로그인을 시도 할 때마다 세션에서).

3

페이지에서 게시물을 올릴 때마다 새 페이지가 나타납니다. NumberOfAttempts 값은 10에 도달하지 않습니다. 세션 변수, 쿠키, 데이터베이스 또는 액세스 할 수있는 다른 장소에 값을 저장하고 매번로드해야합니다.

페이지 수명주기에 대한 추가 정보는이 MSDN 페이지를 참조하십시오. http://msdn.microsoft.com/en-us/library/ms178472(v=vs.100).aspx

다음은 MSDN에서 ASP.NET 상태를 관리하는 옵션에 관한 기사입니다. http://msdn.microsoft.com/en-us/library/z1hkazw7(v=vs.100).aspx

+3

쿠키 사용은 로그인 시도를 추적하고 클라이언트가 쿠키 값을 변경할 수 있으므로 서버가 쿠키를 암호화/서명하지 않은 한 최선의 방법이 아닙니다. – Mark