Login not working

Nuwan

New member
Joined
Apr 15, 2008
Messages
3
Programming Experience
Beginner
I have login interface for Access database
it giving errors pls help
VB.NET:
Imports System.Data
Imports System.Data.OleDb
Public Class frmLogin
    Inherits System.Windows.Forms.Form
    '---------------------------------------------------------
    Private strConnectionString As String = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=D:\Nuwan\Login\Loginbase.mdb;"

    Private objConnection As OleDbConnection
    Private objCommand As OleDbCommand
    Private objDataAdapter As OleDbDataAdapter
    Private objDataSet As DataSet

    Private objDataReader As OleDbDataReader
    '---------------------------------------------------------

    Dim Ctr As Integer
    Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
        'Dim LoginName As String, Password As String
        Dim flag As Boolean
        flag = False
        'LoginName = txtUserName.Text
        'Password = txtPassword.Text
        Ctr = Ctr + 1
        '----------------------------------------
        objConnection = New OleDbConnection(strConnectionString)
        objConnection.Open()

        'Initialize the Command object
        objCommand = New OleDbCommand

        'Set the objCommand object properties
        objCommand.CommandText = "LoginTable"
        objCommand.CommandType = CommandType.StoredProcedure
        objCommand.Connection = objConnection

        'Add the required parameter for the query
        objCommand.Parameters.Add("LoginNameD", OleDbType.Guid, 16).Value = _
            New Guid(txtUserName.Text)

        objDataReader = objCommand.ExecuteReader()

        'If we have data then display the project description
        If objDataReader.HasRows Then
            objDataReader.Read()
            '----------------------------------------
            If txtUserName.Text = objDataReader.Item("PasswordD") Then
                lblMessage.Text = "Welcome to Alarm Monitoring System Data Entry"
                Ctr = 0
                Dim frm As New Form2
                frm.Show()
            Else
                If Ctr < 3 Then
                    lblMessage.Text = "Incorrect User Name or Password - Please Try again"
                    txtUserName.Focus()
                Else
                    MsgBox("Unauthorized Access. Aborting...")
                    Close()
                End If
            End If
        End If
        '----------------------------------------
        'Close the DataReader and Connection
        objDataReader.Close()
        objConnection.Close()

        'Clean up
        objDataReader = Nothing
        objCommand.Dispose()
        objCommand = Nothing
        objConnection.Dispose()
        objConnection = Nothing
        '----------------------------------------
    End Sub

Nuwan:mad:
 
hi,
I found several errors as Totaly above login is not working...

later I could find better login interface with Access database
following is corrected login Interface

pls tell me how to Encrypt the password ?
VB.NET:
    Dim LoginCount As Integer
    Dim formAddAlarm As New formAddAlarm
    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click

        Dim ConString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=""D:\New_Login\Loginbase.mdb"";"
        Dim DBCon As New OleDb.OleDbConnection(ConString)

        If Me.txtUserName.Text = "" Or Me.txtPassword.Text = "" Then
            lblMessage.Text = "You are missing information. Please make sure that both the username and password fields are filled out."
            Me.txtUserName.Focus()
            Return
        End If

        Dim strsql As String = "SELECT [LoginNameD], [PasswordD] FROM LoginTable WHERE [LoginNameD]='" & Me.txtUserName.Text & "' "
        Dim cmd As New OleDb.OleDbCommand(strsql, DBCon)
        Dim drd As OleDb.OleDbDataReader
        Dim validusr As Boolean = False
        Dim HasRows As Boolean = False
        Try
            DBCon.Open()
            drd = cmd.ExecuteReader
            If drd.HasRows Then
                While drd.Read
                    If Me.txtPassword.Text = drd.Item("PasswordD") Then
                        validusr = True
                    End If
                End While
                HasRows = True
            End If
            drd.Close()
        Catch exO As OleDb.OleDbException
            MessageBox.Show(exO.Message)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            If DBCon.State = ConnectionState.Open Then
                DBCon.Close()
            End If
            cmd = Nothing
            drd = Nothing
            DBCon.Dispose()
            'GC.Collect()
        End Try
        LoginCount = LoginCount + 1
        If validusr = True Then
            Me.Hide()
            formAddAlarm.Show()
        ElseIf LoginCount = 3 Then
            MessageBox.Show("Unauthorized Access. Aborting...", "Invalid Info")
            Me.Close()
        ElseIf HasRows = False Then
            lblMessage.Text = "Incorrect User Name  - Please Try again"
            Me.txtUserName.Focus()
            Me.txtUserName.Text = ""
            Me.txtPassword.Text = ""
        Else
            lblMessage.Text = "Incorrect Password - Please Try again"
            Me.txtPassword.Focus()
            Me.txtPassword.Text = ""
        End If

    End Sub
 
Back
Top