login page script required.

gloringg

Member
Joined
Jan 11, 2009
Messages
16
Programming Experience
Beginner
Hi,

I am using Visual basic 2008 express edition with ms access 2003 as database.
I have created the login form in Vb.

Can some one please help me with the backend code for the authentication.

THanks,
 
hi

VB.NET:
Imports System.Data.SqlClient 
 
Public Class Form1 
 
    Private Sub ValidateLogin(ByVal username As String, _ 
ByVal password As String, ByVal accesslevel As String) 
         
        Dim connection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\accounttlb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True") 
        Dim sqlstring As String = String.Format("Select username,password,accesslevel from accpw where username = '{0}' and password ='{1}' ", tbusername.Text, tbpassword.Text) 
         
        Dim command As New SqlCommand(sqlstring, connection) 
 
        Try 
            
            connection.Open() 
            If Not command.ExecuteScalar Is Nothing Then 
                MessageBox.Show("Right, Logged In") 
                Me.Hide() 
                Form2.ShowDialog() 
            Else 
                MessageBox.Show("Wrong, Stay out") 
            End If 
        Catch ex As Exception 
 
            MessageBox.Show(ex.Message) 
            Me.Close() 
        Finally 
            connection.Close() 
        End Try 
 
    End Sub 
 
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click 
        ValidateLogin(Me.tbusername.Text, Me.tbpassword.Text, Me.tbaccesslevel.Text) 
    End Sub 
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click 
        Me.DialogResult = Windows.Forms.DialogResult.Cancel 
        Me.Close() 
    End Sub

I got this from MSDN forum :)
 
Back
Top