0

Hello
Only one time count the msg ok result. but after that when I type wrong username and password coding not work. please help me .........

Try
                Dim erorcunt As Integer
                erorcunt = 0
                Dim myConnection As OleDbConnection
                myConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\DB.accdb;Persist Security Info=False;")
                Dim myCommand As OleDbCommand
                myCommand = New OleDbCommand("SELECT uid,pswrd FROM Users WHERE uid = @username AND pswrd = @UserPassword", myConnection)

                Dim uName As New OleDbParameter("@username", SqlDbType.VarChar)

                Dim uPassword As New OleDbParameter("@UserPassword", SqlDbType.VarChar)

                uName.Value = Username.Text

                uPassword.Value = Password.Text

                myCommand.Parameters.Add(uName)

                myCommand.Parameters.Add(uPassword)

                myCommand.Connection.Open()

                Dim myReader As OleDbDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

                Dim Login As Object = 0

                If myReader.HasRows Then

                    myReader.Read()

                    Login = myReader(Login)

                End If

                If Login = Nothing Then                    

                    Dim msgrlt As MsgBoxResult = MessageBox.Show("Login is Failed...Try again !", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)

                    If msgrlt = MsgBoxResult.Ok Then
                        erorcunt = erorcunt + 1

                    End If

                    Username.Clear()
                    Password.Clear()
                    Username.Focus()

                    Label3.Text = erorcunt
                    If erorcunt = 3 Then
                        Application.Exit()
                    End If
                Else

                    ProgressBar1.Visible = True
                    ProgressBar1.Maximum = 5000
                    ProgressBar1.Minimum = 0
                    ProgressBar1.Value = 4
                    ProgressBar1.Step = 1
                    Me.Hide()
                    For i = 0 To 5000
                        ProgressBar1.PerformStep()
                    Next

                    frmmain.ToolStripStatusLabel2.Text = Username.Text
                    Me.Hide()

                    frmmain.Show()
                    Me.BackColor = Color.Red
                End If
                myCommand.Dispose()
                myConnection.Close()
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try

Edited by Jayanta_1

2
Contributors
5
Replies
32
Views
1 Week
Discussion Span
Last Post by Jayanta_1
0

No error message show. Application not colosed after 3 times wrong username and password enter. I used label3 for show the attempt counting number, 1st time show the number 1, but next 2 time not incrieasd the number I think that means not count the msg-result (I am not sure). So, Application Not Closed

0

The number does not increment because the error counter in erorcunt is defined locally, so each time there is a try for username and password erorcunt value is 0 and incremented to 1. Define this variable errorcntat class level.

0

Thanks sir,

Define this variable errorcntat class level.

I Just Do it as per your order and DONE it.
Again Thanks -

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.