Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to make login form in vb.net????plese give me proper coding for that and appropriate database for that........ i hope it will help me thanks....
Posted

 
Share this answer
 
Imports System.Data.Odbc
Imports MySql.Data.MySqlClient
Imports System.Net.Mail
Public Class Login_Form
Dim errorclose = 1
Private Sub Login_Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Private Sub Login_Form_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Enter Then
Login1_Click(sender, e)
ElseIf e.KeyCode - Keys.Enter Then
Logout1_Click(sender, e)
End If
End Sub
Private Sub Login1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login1.Click
If txtUsername.Text = "" Or txtPassword.Text = "" Then
MsgBox("Please enter UserName and Password")
txtUsername.Focus()
Else
'Connects To the Database
Try
Dim connectionstring As String = "Driver=MySQL ODBC 3.51 Driver;Server=192.168.1.12;port=3306;uid=root;pwd=admin;Database=elcott;"
Dim conn As New OdbcConnection(connectionstring)
conn.Open()
Dim myAdapter As New OdbcDataAdapter
Dim sqlquerry = "Select * From userpass where Username = '" + txtUsername.Text + "' And Password= '" + txtPassword.Text + "'"
Dim myCommand As New OdbcCommand
myCommand.Connection = conn
myCommand.CommandText = sqlquerry
'Starting The Query
myAdapter.SelectCommand = myCommand
Dim mydata As OdbcDataReader
mydata = myCommand.ExecuteReader()
'To check the Username and password and to validate the login a
If mydata.HasRows = 0 Then
If errorclose > 2 Then
MsgBox("The system is closing", MsgBoxStyle.Critical)
Application.Exit()
Else
errorclose += 1
MsgBox("Incorrect password. Please check.", MsgBoxStyle.Critical)
txtUsername.Focus()
End If
Else
Client_chat.txtChatUsername.Text = txtUsername.Text
Client_Main_Window.Show()
Me.Hide()
End If
conn.Close()
Catch myerror As OdbcException
MsgBox
End Try
VB
txtUsername.Text = ""
        txtPassword.Text = ""
    End Sub
    Private Sub Logout1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Logout1.Click
        Application.Exit()
    End Sub
End Class
 
Share this answer
 
Comments
vinoth1218 6-Mar-13 3:24am    
Client_chat.txtChatUsername.Text = txtUsername.Text
Client_Main_Window.Show() wat this lines mean ??? plz tel client_chat.means ??

thank u in adavance
Please follow up below link.

You will see how you create a Login form with many controls.

1. Encrypted Passwords
2. Login attempts counting
3. Blocking any UN-authorized login attempts

samplevbcodes.blogspot.com

http://www.samplevbcodes.blogspot.com/
 
Share this answer
 
This might help. It's in C#, but it's easy to convert with one of the free online converters:

User Login For WinForm Applications[^]
 
Share this answer
 
Try reading this: Introduction to Membership[^] - it will guide you throughthe whole process.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900