2013-11-04 3 views
0

내 로그인 기능에 로그인 시도 횟수를 추가하고 싶습니다. 사용자가 잘못된 사용자 이름과 암호를 세 번 입력하면 프로그램이 닫히고 메시지가 표시됩니다. 여기에서 로그인 버튼에 대한 내 코드에 내 Form1.vb :로그인 시도 횟수를 계산하는 방법 Visual Basic

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    If TextBox1.Text = "13Mendv" And TextBox2.Text = "Admin123" Or 
     TextBox1.Text = "Admin" And TextBox2.Text = "Admin123" Or 
     TextBox1.Text = "13PateS" And TextBox2.Text = "Staff123" Or 
     TextBox1.Text = "13KhetP" And TextBox2.Text = "Member123" Or 
     TextBox1.Text = "13PateN" And TextBox2.Text = "Scorer123" Or 
     TextBox1.Text = "13ChatP" And TextBox2.Text = "Captain123" Or 
     TextBox1.Text = "13BonnN" And TextBox2.Text = "Captain123" Or 
     TextBox1.Text = "13EarlJ" And TextBox2.Text = "Captain123" Or 
     TextBox1.Text = "13RajaA" And TextBox2.Text = "Captain123" Or 
     TextBox1.Text = "1" And TextBox2.Text = "1" Or 
     TextBox1.Text = "13SchaJ" And TextBox2.Text = "Captain123" Then 
     Timer1.Start() 'Timer on Form1.vb show 
     ProgressBar1.Show() 'Progress bar on Form1.vb show 
     Label8.Show() 'Label8 on Form1.vb show 
     Button4.Show() 'Button4 on Form1.vb show 

    Else 
     If TextBox1.Text = "" And TextBox2.Text = "" Then 
      MsgBox("No Username and/or Password Found!", MsgBoxStyle.Critical, "Error") 'If statement for checking if there is any input in either username or password entry field 
     Else 
      If TextBox1.Text = "" Then 
       MsgBox("No Username Found!", MsgBoxStyle.Critical, "Error") 'Message box no username found 
      Else 
       If TextBox2.Text = "" Then 
        MsgBox("No Password Found!", MsgBoxStyle.Critical, "Error") 'Message box no password found 
       Else 
        MsgBox("Invalid Username And/Or Password!", MsgBoxStyle.Critical, "Error") 'Message box invlaid username and or password 
        TextBox2.Clear() 
       End If 
      End If 
     End If 
    End If 

End Sub 

내가 제대로 3 로그인 시도 실패 자신의 사용자에게 통지 코드로 카운트를 추가하기 위해 무엇을 할 수 있는가?

+0

'가'실패 개인 nCount 정수로 = 0' 각 시간 nCount = 1 '이 (3)에 – Plutonix

+0

I를 얻을 때 다음 응용 프로그램을 종료 누군가 거기서 누군가 당신의 사용자 이름과 패스워드를 방송하는 것을 확신합니다. :) – cHao

+0

도움을 주셔서 감사합니다. 매우 환영합니다. –

답변

0

으로 여러 사람이, 당신은 변수 (cntAttempts)를 만들 수 있습니다 제안했다 그 추적 Button1.Click을 를 처리 사용자가 로그인을 시도하는 횟수를 계산하고, 카운트가 3에 도달하면 프로그램이 종료됩니다. 이처럼 :

Private cntAttempts = 0 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    If ... Then 
     Timer1.Start() 'Timer on Form1.vb show 
     ProgressBar1.Show() 'Progress bar on Form1.vb show 
     Label8.Show() 'Label8 on Form1.vb show 
     Button4.Show() 'Button4 on Form1.vb show 

    Else 
     cntAttempts += 1 
     If cntAttempts = 3 Then 
      MessageBox.Show("login failed") 
      Me.close() 
     End If 
     If TextBox1.Text = "" And TextBox2.Text = "" Then 
      ... 
     Else 
      ... 
     End If 
    End If 

End Sub 

HTH

+0

도움을 주셔서 감사합니다. 이제 작동하게되었습니다. –

0

정수로 cnt를 추가하고 cnt가 < = 3이 될 때까지 증가시킵니다.

개인 서브를 Button1_Click (은 System.Object로 ByVal의 보낸 사람, 경우 System.EventArgs으로 ByVal의 e)이

'Dim cnt As Integer = 0 
    If cnt <= 3 Then 
     If TextBox1.Text = "13Mendv" And TextBox2.Text = "Admin123" Or 
      TextBox1.Text = "Admin" And TextBox2.Text = "Admin123" Or 
      TextBox1.Text = "13PateS" And TextBox2.Text = "Staff123" Or 
      TextBox1.Text = "13KhetP" And TextBox2.Text = "Member123" Or 
      TextBox1.Text = "13PateN" And TextBox2.Text = "Scorer123" Or 
      TextBox1.Text = "13ChatP" And TextBox2.Text = "Captain123" Or 
      TextBox1.Text = "13BonnN" And TextBox2.Text = "Captain123" Or 
      TextBox1.Text = "13EarlJ" And TextBox2.Text = "Captain123" Or 
      TextBox1.Text = "13RajaA" And TextBox2.Text = "Captain123" Or 
      TextBox1.Text = "1" And TextBox2.Text = "1" Or 
      TextBox1.Text = "13SchaJ" And TextBox2.Text = "Captain123" Then 
      Timer1.Start() 'Timer on Form1.vb show 
      ProgressBar1.Show() 'Progress bar on Form1.vb show 
      Label8.Show() 'Label8 on Form1.vb show 
      Button4.Show() 'Button4 on Form1.vb show 
     Else 
      cnt = cnt + 1 
      If TextBox1.Text = "" And TextBox2.Text = "" Then 
       MsgBox("No Username and/or Password Found!", MsgBoxStyle.Critical, "Error") 'If statement for checking if there is any input in either username or password entry field 
      Else 
       If TextBox1.Text = "" Then 
        MsgBox("No Username Found!", MsgBoxStyle.Critical, "Error") 'Message box no username found 
       Else 
        If TextBox2.Text = "" Then 
         MsgBox("No Password Found!", MsgBoxStyle.Critical, "Error") 'Message box no password found 
        Else 
         MsgBox("Invalid Username And/Or Password!", MsgBoxStyle.Critical, "Error") 'Message box invlaid username and or password 
         TextBox2.Clear() 
        End If 
       End If 
      End If 
     End If 
    End If 
End Sub` 
+0

죄송합니다.이 기능이 작동하지 않아 카운터가 3에 도달하면 프로그램을 닫는 데 도움이되지 않습니다. 도움을 주시면 더 큰 도움을받을 수 있습니다. –

+0

지금 답변을 드리겠습니다. 위의 고맙습니다 again –

0
Dim a =0 

    If txtname.Text = "yourUsername" And txtpass.Text = "yourPassword" Then 
    Msgbox("Acces Granted") 
    a=0 
    Elseif txtname.Text <> "yourUsername" Or txtpass.Text <> "yourPassword" Then 
    a = MsgBox("INVALID USERNAME AND PASSWORD") + a 

    End if 

    If 
    a = 3 Then 
    End 

    End if 
+0

필요한 것은 정수일 때 'a'를 Object로 선언하고 있습니다. 또한 열거 형 ('DialogResult')의 값을'a'에 추가하고 항상 '1'이라고 가정합니다. – JoelC

+0

도와주세요. [http://stackoverflow.com/a/26203112/3902343] –

1
Public Class Form1  
    Dim attempts As Integer = 0 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
     Dim user As String 
     user = TextBox1.Text 
     If user = "Jhayboy" Then 
      MsgBox("Access Granted") 
      Form2.Show() 
      Me.Hide() 

     ElseIf attempts = 3 Then 
      MsgBox("Maximum count of retries(3),And you'reach the maximum attempts!Try again later", MsgBoxStyle.Critical, "Warning") 
      Close() 
     Else 
      MsgBox("Username and Password is incorrect! re-enter again you currently have reached attempt " & attempts & " of 3.") 

      attempts = attempts + 1 
      TextBox1.Text = "" 
      TextBox1.Focus() 

     End If 
    End Sub 
End Class 
관련 문제