How to validate a username password and usertype login in Vb.net?

5 pts.
Tags:
2012
VB.NET Express Edition

How to validate a username and password to login and then also check the usertype, based on which different events can be triggered?for example admin has certain privileges and normal user has different privileges.

Public Class Login

    Dim con As New OleDb.OleDbConnection
    'new connection to database
    Dim dbprovider As String
    'to gets the probider name
    Dim dbsource As String
    'to gets the database provider name
    Dim ds As New DataSet
    'dataset to table
    Dim da As OleDb.OleDbDataAdapter
    'databaseAdapter to dataset and database
    Dim sql As String
    'sql command
    Dim usrname1, pswd1, usrtype As String
    Dim maxrows, incdec As Integer
    'string variables
  
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'validation of username and password
        If txtb_uname.Text = usrname1 And txtb_pwd.Text = pswd1 Then
                If usrtype = "admin" Then

                    Score.Show()
                    Score.btn_delete.Enabled = False
                    Score.btn_update.Enabled = False
                    Score.Button2.Enabled = False
                    Score.Button1.Enabled = False


                Else
                    MsgBox("invalid usertype")
                End If
                'username and password correct go to the netx page
        ElseIf txtb_uname.Text = usrname1 And txtb_pwd.Text = "" Then
                MsgBox("Enter Password")
                'blank password control
        ElseIf txtb_uname.Text = "" And txtb_pwd.Text = pswd1 Then
                MsgBox("Enter Username")
                'blank username control
        ElseIf txtb_uname.Text = usrname1 And txtb_pwd.Text <> pswd1 Then
                MsgBox("Invalid Password")
                'incorrect pasword
        ElseIf txtb_uname.Text <> usrname1 And txtb_pwd.Text = pswd1 Then
                MsgBox("Invalid Username")
                'incorrect username
        ElseIf txtb_uname.Text = "" And txtb_pwd.Text = "" Then
                MsgBox("enter Username")
                'blank username and password

        Else
                MsgBox("Invalid Username & or Password")
                'incorrect username and password

        End If


    End Sub

    Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        dbprovider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
        'database provider name
        dbsource = "Data Source = C:Userss562DesktopDB1.accdb"
        'file name of the database source
        con.ConnectionString = dbprovider & dbsource
        'to access database from form
        con.Open()
        'MsgBox("DAtabase open")
        sql = "select * from login"
        'select all records

        da = New OleDb.OleDbDataAdapter(sql, con)
        'execute sql command
        da.Fill(ds, "login1")
        maxrows = ds.Tables("login1").Rows.Count
        'count table rows
        ' incdec = 0
        'incdec = incdec + 1
            pswd1 = ds.Tables("login1").Rows(0).Item(2)
            'table value stored in pswd1
            usrname1 = ds.Tables("login1").Rows(0).Item(1)
            'table value stored in usrname1
            usrtype = ds.Tables("login1").Rows(0).Item(0)
    End Sub
   
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    End Sub

End Class

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following