none
How to make login form in vb 2010 express that is link in database access 2007

    Question

  • Please help me to make a login form. The project must have different user and each has username and password will be saved in my database but only the admin can add users. Thank you in advance.
    Monday, January 02, 2012 10:41 AM

Answers

  • Hi
    Welcomes you to MSDN forums
    
    Check this..
    
    
    Imports System.Data.OleDb
    Imports System.Data
    
    Private sub Validate()
        Dim strUserName as String=txtUserName.Text
        Dim strPassword as String=txtPassword.Text
       Try
        ' Define a connection object
        Dim dbConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Password=" & strPassword & ";User ID= " & strUserName & ";Data Source=YourDbName.mdb")
        dbConn.open()
        Catch ex As Exception
         ' An error occurred. Show the error message
        MessageBox.Show(ex.Message,"Login Failed",MessageBoxButtons.Ok, MessageBoxIcon.Error)
         End Try
    End Sub
    
    
    By
    A Pathfinder..
    JoSwa
    
    


    If you find an answer helpful, click Vote as helpful button. If you find an answer to your question, Click mark it as the answer.
    Monday, January 02, 2012 10:57 AM
  • hi

    assume that you have a table called tbluser with UserId, FirstName, LastName, UserName, Password, IsAdmin Fields. the UserId data type is int and it's also the primary key of the table and it's identifier property is true.  the IsAdmin data type is bit witch will determined if the user is admin or not. now we need a function to check if the username exists in the tbluser table and then if the password that user entered is correct or not.

    here is the function

     Private Function Authenticate(ByVal UserName As String, ByVal Password As String) As Boolean
            Dim command As New SqlCommand
            Dim connection As New SqlConnection("Your Connection String Here")
            Dim datareader As SqlDataReader
            With command
                .CommandType = CommandType.Text
                .CommandText = "select password from tbluser where UserName = @UserName"
                .Parameters.AddWithValue("@UserName", UserName)
            End With
            If connection.State = ConnectionState.Closed Then
                connection.Open()
            End If
            datareader = command.ExecuteReader
            datareader.Read()
            If datareader.HasRows = False Then
                Return False
            Else
                If Password.Equals(datareader("Password").ToString()) Then
                    Return True
                Else
                    Return False
                End If
            End If
        End Function
    

    you will authenticate your user based on the return value of this function. read this article to understand user authentication in .net

    How To Implement Forms-Based Authentication in Your ASP.NET Application by Using Visual Basic .NET

    Monday, January 02, 2012 2:36 PM

All replies

  • Hi
    Welcomes you to MSDN forums
    
    Check this..
    
    
    Imports System.Data.OleDb
    Imports System.Data
    
    Private sub Validate()
        Dim strUserName as String=txtUserName.Text
        Dim strPassword as String=txtPassword.Text
       Try
        ' Define a connection object
        Dim dbConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Password=" & strPassword & ";User ID= " & strUserName & ";Data Source=YourDbName.mdb")
        dbConn.open()
        Catch ex As Exception
         ' An error occurred. Show the error message
        MessageBox.Show(ex.Message,"Login Failed",MessageBoxButtons.Ok, MessageBoxIcon.Error)
         End Try
    End Sub
    
    
    By
    A Pathfinder..
    JoSwa
    
    


    If you find an answer helpful, click Vote as helpful button. If you find an answer to your question, Click mark it as the answer.
    Monday, January 02, 2012 10:57 AM
  • where should i put this?
    Monday, January 02, 2012 11:10 AM
  • hi

    assume that you have a table called tbluser with UserId, FirstName, LastName, UserName, Password, IsAdmin Fields. the UserId data type is int and it's also the primary key of the table and it's identifier property is true.  the IsAdmin data type is bit witch will determined if the user is admin or not. now we need a function to check if the username exists in the tbluser table and then if the password that user entered is correct or not.

    here is the function

     Private Function Authenticate(ByVal UserName As String, ByVal Password As String) As Boolean
            Dim command As New SqlCommand
            Dim connection As New SqlConnection("Your Connection String Here")
            Dim datareader As SqlDataReader
            With command
                .CommandType = CommandType.Text
                .CommandText = "select password from tbluser where UserName = @UserName"
                .Parameters.AddWithValue("@UserName", UserName)
            End With
            If connection.State = ConnectionState.Closed Then
                connection.Open()
            End If
            datareader = command.ExecuteReader
            datareader.Read()
            If datareader.HasRows = False Then
                Return False
            Else
                If Password.Equals(datareader("Password").ToString()) Then
                    Return True
                Else
                    Return False
                End If
            End If
        End Function
    

    you will authenticate your user based on the return value of this function. read this article to understand user authentication in .net

    How To Implement Forms-Based Authentication in Your ASP.NET Application by Using Visual Basic .NET

    Monday, January 02, 2012 2:36 PM
  • Hello

    It is my first time to use database... Is this code applicable to New Microsoft Office Access 2007 Database?? 

    Tuesday, January 03, 2012 12:25 AM
  • by the way where should i put this, inside the visual basic 2010 express or Microsoft Office Access 2007 Database?
    Tuesday, January 03, 2012 12:52 AM
  • If you cant answer this question then, you should just let it go. Stick to a hobby your familiar with. Programming will kick your butt if your honestly asking this. 
    Tuesday, September 24, 2013 2:52 PM
  • If you cant answer this question then, you should just let it go. Stick to a hobby your familiar with. Programming will kick your butt if your honestly asking this. 

    Thanks, we all wanted to know this about a 20 month old thread.

    SCNR


    Armin

    Tuesday, September 24, 2013 3:01 PM
  • If you cant answer this question then, you should just let it go. Stick to a hobby your familiar with. Programming will kick your butt if your honestly asking this. 

    Thanks, we all wanted to know this about a 20 month old thread.

    SCNR


    Armin


    So happy I did not reply, had not noticed the last reply date till you pointed it out :-)

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Tuesday, September 24, 2013 5:55 PM
    Moderator