Smart Tech Diary

The Smart Tech Diary

We recommend Divi Theme For WordPress

  • HOME
  • ABOUT
  • Topics
    • Programming
    • Computing
    • Hacking
    • Electronics
    • Web Design
  • CONTACT
  • Subscribe
  • Hacking Disclaimer
  • Privacy
You are here: Home / Programming / How to develop a commercial e-Statement solution in vb6 step by step – Part 5 – Login Form in vb6 using SQL

How to develop a commercial e-Statement solution in vb6 step by step – Part 5 – Login Form in vb6 using SQL

11th May 2015 by Abdalla Nizar 1 Comment

Building a Commercial e-Statement Application in VB 6 – Login Form in VB6 using SQL

During our last post, we created Modules and Menu for the e-statement application. Today we are going to create the login form in vb6 using sql for our application which will have two user types:

  1. Operator
  2. Administrator

The Operator(s) will have no security rights to access the Application Configurations module. This module will be restricted only to the system Administrator(s). In this post we are going to add the test users directly in the database.

ATTENTION: For you to understand this post you need to look at the previous posts if you haven`t done so already.

In Summary, we are going to do the following in this article

  1. Add two users into the Users table
  2. Create a Login Form
  3. Connect the Login Form to the SQL Server database
  4. Authenticate users
  5. Check if logged in user is an Administrator or Operator and give access to the correct system module(s)

Without wasting any more time lets login to the Microsoft SQL Server with the ‘sa’ username and password.

Add two users into the Users table

Go to the “SmartMail” database expand on the Tables and right click the Users table and choose “Edit Top 200 Rows”.

www.smarttechdiary.com Developing a commercial e-statement application for banks and SACCOs

Add two usernames as below:

The “Admin” username has been given the admin rights on the “isAdmin” column.

www.smarttechdiary.com Developing a commercial e-statement application for banks and SACCOs

Once that is done we can now create the Login Form and start coding.

Create a Login Form

www.smarttechdiary.com Developing a commercial e-statement application for banks and SACCOs

Open the SmartMail project and add a new Form.

Add the following to the form

  • One Data combo

Name the Data combo as “dcUser”. This will have the drop down list of all the usernames in the database

  •  One Textbox

Name the Textbox as “txtPass” , Caption leave it empty

  • Two Command buttons

Name one as “cmdLog” and Caption “Login”. The second one name it as “cmdCancel” and caption “Cancel”

  • Three Label

These three labels will have the following Caption: one is for the “Username” second “Password” and third “Please select your username and enter your password in the space provided below.”

See the Login Form below

www.smarttechdiary.com Developing a commercial e-statement application for banks and SACCOs

I have added an Image of a padlock and an extra label at the bottom to make the Login Form more attractive.

Once you have the controls on the form its time to code.

Form Load Event

Double click your Login form and add the below code:

'eStatement Application Development
'www.smarttechdiary.com

Private Sub Form_Load()
 'Get usernames from the Users table
 bind_dc "SELECT * FROM Users", "Username", dcUser, "ID"
End Sub

cmdLogin Button

Double click on the Login button and add the following code:

'eStatement Application Development
'www.smarttechdiary.com

Private Sub cmdLog_Click()
 'Verify
    If dcUser.Text = "" Then dcUser.SetFocus: Exit Sub
    If txtPass.Text = "" Then txtPass.SetFocus: Exit Sub
    Dim strPass As String
    Dim isDisabled As String
    
    'Check if use has been disabled
    isDisabled = getValueAt("SELECT IsDisabled FROM Users WHERE ID='" & dcUser.BoundText & "'", "IsDisabled")
    If isDisabled = "True" Then
    MsgBox "Sorry Your Username Has Been Disabled,Please Contact The System Administrator", vbCritical, "Login Failure"
    Exit Sub
    End If
    strPass = getValueAt("SELECT Username,Password FROM Users WHERE ID='" & dcUser.BoundText & "'", "Password")
    If LCase(txtPass.Text) = LCase(strPass) Then
        With CurrUser
           .USER_NAME = dcUser.Text
           .USER_PK = dcUser.BoundText
           .USER_ISADMIN = getValueAt("SELECT ID,IsAdmin FROM Users WHERE ID=" & dcUser.BoundText, "IsAdmin")
           
        End With
        Unload Me
    Else
        MsgBox "Invalid password.Please try again!", vbExclamation
        txtPass.SetFocus
        LoginTrials = LoginTrials + 1
        If LoginTrials = 3 Then
        MsgBox "You Have Exceeded Your Login Trials!The System Will Now Exit", vbCritical, "Exceeded Login Trials"
        End
        End If
        
    End If
    strPass = vbNullString

End Sub

cmdCancel Button

The Cacel button closed the Login form when a user chooses not to Login to the e-Statement system
Double click on the Cancel button and add the following code:

'eStatement Application Development
'www.smarttechdiary.com

Private Sub Form_Unload(Cancel As Integer)
    Unload Me
End Sub

Other Subroutines

Add the following form to your form to complete this login system

'eStatement Application Development
'www.smarttechdiary.com

Option Explicit
Dim LoginTrials As Byte


Private Sub cmdCancel_Click()
    MAIN.CloseMe = True
    Unload Me
End Sub

Private Sub txtPass_Change()
    txtPass.SelStart = Len(txtPass.Text)
End Sub


Private Sub txtPass_GotFocus()
    HLText txtPass
End Sub

Test Login Form in VB6 Using SQL

If you have been following each step from the beginning of this series, you should have a working Login form by now.
Click on run to run your application and Login using your username and password.

www.smarttechdiary.com Developing a commercial e-statement application for banks and SACCOs

Mine is working nicely , if you any problem and need help you can contact me and I will try my best to help you.
www.smarttechdiary.com Developing a commercial e-statement application for banks and SACCOs

I hope you have enjoyed this article, if you have suggestions please leave your comments below. Until next time do have a nice week. Please share with your friends.

Share this:

  • Reddit
  • Email
  • Print
  • WhatsApp
  • Skype

Related

Filed Under: Programming Tagged With: bank estatement, bank statement, bank statement dbs, E-Statement, estatement, online estatement

Trackbacks

  1. How to develop a commercial e-Statement solution in vb6 step by step - Part 7 - VB 6 User Management System with SQL Server - Smart Tech Diary says:
    1st June 2015 at 1:50 pm

    […] Login Form With SQL Database […]

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

WordPress-Security-For-Non-Geeks

Subscribe to Download The E-Book

* indicates required

Recent Posts

  • Why I will never use nulled WordPress themes again
  • New WordPress 4.8 has been released, Don’t Be Late
  • WikiLeaks reveals Grasshopper Malware, the CIA’s Windows hacking tool
  • The Ultimate WordPress Security Guide 2017 | How To Secure Your WordPress Website
  • How to purchase data bundle for Airtel postpaid lines

Categories

  • Computing
  • Databases
  • Digital Marketing
  • Electronics
  • Hacking
  • Kenya How Tos
  • Programming
  • Web Design
  • Wordepress Security
  • WordPress

Copyright © 2023 · The Smart Tech Diary