Monday, June 2, 2014

Login System in Visual Basic .NET and Microsoft Access

Information is very important to us as human being this information is very useful in making decisions in our day to day lives.  Now every individuals is equip with different devices and gadgets which enables them to communicate, read news from the Internet, do some buying and selling in the Internet.  But the biggest question is how secure our information whether it is stored in the Internet or on our own computer.  Generally speaking one of the most important issues is all about computer security that most people is not bothered with. Why because some people think if you use difficult username and password in your computer or your account the in web you are already secure and having a peace of mind because you know no body has the access to your account but only you alone.

Again this presumption is not correct most of the time, hackers and other people that has a high level of technical skills and knowledge in computers were able to gather information about any person and use those information for their own benefit. We have heard many times hackers able to get and stoles thousands or even millions of credit card numbers from banks and financial institution worldwide and sold this credit card numbers including the information of the person online with the right price you can get one and use it in your shopping or  business transactions. Why this things happened because there are security issues and problems were discovered in banks information system that hackers will able to exploit. Sometimes this loopholes in the system was also discovered by bank employees or IT personnel in the bank that they have a direct access in the system.  As I said in any bank or even financial institution they should practice security audit from time to time to know what are the problems or bugs in their system to avoid to be the next victim of hackers or intruders.

In this article I will discuss and show you how to create a database drive login system using Microsoft Visual Basic .NET as my programming language and Microsoft Access 2007 as my database.  I called this program login system using Microsoft Visual Basic 2010 and Microsoft Access 2007.  To be honest this is my first database application that I wrote using Visual Basic .NET because most of the time I used Microsoft Visual Basic 6 as my tool in creating customized database application for my clients here in the Philippines.  But I think learning the new version of Visual Basic is very important skills in today's information technology driven society and also to upgrade my skills in programming tool.   By contrary database programming in Visual Basic .NET is much easier compared to Visual Basic 6 why because all the necessary commands for database access is already built in and the user interface is excellent in my own opinion.
I started designing first my user interface in a form I named the form login system in its caption. The background of the form I choose light green it is my own preference  you can select the colour that you want in your program it doesn't matter it is more of the personal choose. Next in line I draw two text box the txtusername and txtpassword that will accept the user name and password of the user. I also write the labels to give the use the idea what to do the first label asking the user to enter the user name, the second label is asking the user to enter the password.  There are also two command buttons the OK and CLOSE. The OK command button if the user already type the username and password  and then click the OK button it will check if the username and password exist in our table named login in our Microsoft Access database named user. If the user choose the close command button the program will close and it will return to our windows operating system. In my case the computer that I am using in writing and developing this program I am using  Microsoft Window 8.


About the code I make sure the code is short and easy to understand by my fellow programmer. I am using connection string to allow me to connect Microsoft access 2007 database to my visual basic code as usually we must use SQL statement to do some queries in our table. In our SQL statement we issue a command SELECT username,password FROM login where username=? and password=? this statement tell SQL that we select fields username and password to check if the username and password provided by our user in our form is correct or not.  I also use a function in Visual Basic .NET to convert username and password into lowercase the command is ToLower(). Every time a user type username and password even the user type in capital or combination of uppercase and lowercase our program will convert all the user name and password into lower case. If the user name and password is correct our program will congratulate the user is not it will give a chance to the user to key in once again the correct user name and password in our program.




Sample Output of Our Program


Program Listing


Imports System.Data.OleDb
Public Class frmlogin
    Private Sub Btn_login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_login.Click
        Dim con As New OleDb.OleDbConnection
        con.ConnectionString = "PROVIDER=Microsoft.JET.OLEDB.4.0;Data Source = ..\user.mdb"
        Dim cmd As OleDbCommand = New OleDbCommand("SELECT username,password FROM login where username=? and password=?", con)

        cmd.Parameters.AddWithValue("username", Me.txt_username.Text)
        cmd.Parameters.AddWithValue("password", Me.txt_password.Text)

        Try
            con.Open()
            Dim read As OleDbDataReader = cmd.ExecuteReader()

            If read.HasRows Then
                read.Read()

                If Me.txt_username.Text.ToLower() = read.Item("username").ToString And Me.txt_password.Text.ToLower = read.Item("password").ToString Then
                    MsgBox("You have login in the system successfully.", MsgBoxStyle.Information, "For your information")
                    Me.Hide()

                ElseIf String.IsNullOrEmpty(Me.txt_username.Text) Or String.IsNullOrEmpty(Me.txt_username.Text) Then
                    MsgBox("Please make sure the username and password is not empty.", MsgBoxStyle.Exclamation, "Warning")
                End If

            Else
                MsgBox("Username and Password is incorrect. " & vbCrLf &
                       " Access Denied !!! Please Try Again.", MsgBoxStyle.Exclamation, "Warning")
                Me.txt_username.Text = ""
                Me.txt_password.Text = ""
                Me.txt_username.Focus()
            End If

            read.Close()

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            con.Close()
        End Try

    End Sub

    Private Sub btn_close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_close.Click
        End
    End Sub
End Class







No comments:

Post a Comment