Sunday 12 July 2015

Coding and Designing Login Form Without Database in VB.NET

Coding and Designing Login Form




















Steps:

  • Add a new Form to your project.
  • Add a Label for Header and change the Text properties  to Login
  • Add two Labels - change the Text properties and set it to username and password.
  • Add two Textboxes - change the design name and set it txtUser and txtPass.
  • Add three Buttons - Change the Text properties and set it  to login.reset and Exit.  Also change the design name to btnLogin, btnReset,btnExit respectively.

Coding:


Public Class frmLogin
    Dim count As Double = 0

    Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
        Me.Close()

    End Sub

    Private Sub btnReset_Click(sender As System.Object, e As System.EventArgs) Handles btnReset.Click
        txtPass.Clear()
        txtUser.Clear()
        txtUser.Focus()

    End Sub

    Private Sub btnLogin_Click(sender As System.Object, e As System.EventArgs) Handles btnLogin.Click
        Dim user, pass As String
        user = "root"
        pass = "password"

        If txtUser.Text = user And txtPass.Text = pass Then

            MessageBox.Show("welcome user")
        Else
            'count = count + 1
            count += 1
            Dim maxcount, remain_count As Double
            maxcount = 3
            remain_count = maxcount - count

            MessageBox.Show("wrong username or password" & "" & remain_count & "tries left")
            txtPass.Clear()
            txtUser.Clear()
            txtUser.Focus()

            If count = maxcount Then
                MessageBox.Show("Max try exceeded")
                Application.Exit()

            End If



        End If


    End Sub

    Private Sub frmLogin_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.AcceptButton = btnLogin

    End Sub
End Class


Correct username and password









































Wrong username and password 














































Watch Video Tutorial here

   

No comments:

Post a Comment