Barangay Management System Development Part 5 – Login Form

Barangay Management System Development Part 5 – Login Form

Before you read this tutorial on how to make a login form for barangay management system make sure you have downloaded the resources from the previous part which is the database connection part.

In the part 4 of our tutorial, we have established a connection between visual basic and our mysql database. We have created a module which contains the code to connect vb and mysql, we have also created a login form that will serve as the start-up form of our project and to test if the configuration of or connection string is correct or not.

The next thing to do is to write a code for our login form and this will be our topic for this tutorial.

After you have downloaded the resources, open the mis.vbp project.

We need to design our login form; we need the following form controls:

  • 2 lables – label for username and password
  • 2 text boxes – text box for username and password
  • 2 command buttons – 1 button for login and 1 button to cancel or close the login form

We will also apply proper naming convention for our form controls:

  • txtUsername is the name of the textbox for username
  • txtPassword is the name of the textbox for password
  • cmdOk is the name of the button for verifying our login credentials
  • cmdCancel is the name of the button to close the form

The output of the form should look like the image below, or you are free to design your login form by adding images to the button or any design you want. In our case we will create a simple login form design because our focus is to have a functional login form that connects to our database.

Barangay Management System Development Login Form
Barangay Management System Development Login Form

Once the design is done, we need to write a code that will look and match for the username and password combination stored in our table. Double click the cmdOk button and paste the code below

Private Sub cmdOk_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "Select * from tbl_useraccounts where username='" & txtUsername.Text & "' and password='" & txtPassword.Text & "'", conn, adOpenKeyset, adLockOptimistic, adCmdText
If Not rs.EOF Then
MsgBox "Login successfull, welcome to barangay system.", vbInformation, ""
Frm_Main.Show
Unload Me
Else
MsgBox "Invalid User Name or Password. Try Again.", vbCritical, "Login failed"
txtUsername.SetFocus
End If
End Sub

Code explanation:

The code above will look for records in the tbl_useraccounts, specifically in the username and password column of the table. The login form will serve as the user input and the code will match it if the username and password entered by the user matches a single record.

To close the form, write the code below in the cmdCancel button.

Private Sub cmdCancel_Click()
Unload Me
End Sub

To test our code; we need to manually add a record in our table. Open your xampp control panel and make sure the apache and mysql service are up and running.

Next is to open your browser and type http://localhost/phpmyadmin/, the url will redirect you to the PHPMyAdmin tools that allows us to manage our database. Next is to open barangaysysdb, this is the database that we have created in the 2nd part of our tutorial.

Then open the tbl_useraccounts and click the Insert Tab. A full video tutorial on the development of barangay system will be released once this documentation is finally done.

Refer to the image below for the information to be added in the record. Don’t forget to click the Go button.

Barangay Management System Development Insert User Record
Barangay Management System Development Insert User Record

After we have manually added a record, it’s time to test our login code.

The username and password is admin. If the input of the user is admin for the username and password the system will display the message “Login successfull, welcome to barangay system.” and the form will close and it will open another form which is the main form otherwise the system will display the message “Invalid User Name or Password. Try Again.”

Note: we need to create another form (MDI form) that will serve as the main form of the system. Save the form as Frm_Main

Barangay Management System Development Add MDI Form
Barangay Management System Development Add MDI Form

This is the end of the part 5 of our tutorial; next tutorial is on how to setup our main form and the navigations of our system.

Download Source code reference

You may also visit the following articles related to the barangay information system.

Barangay Records Management Features and User Interface

City Wide Barangay Management System in PHP and MySQL

see you on the part 6 of this free tutorial.

iNetTutor.com

, ,

Post navigation