i dont know how to make my log in system to have a multiple users with different access levels. for example when the admin logs in it can access all the features of the system and if the ordinary users logs in some of the features are disabled.

my log in system has currently one user that can log in and it is the admin.. i want to have multiple users who can access it.

You need to define wich menus/forms/functionalities should be permitted to each access level.
Also you need todefine a config file or DB table where to relate each username to the corresponding access level.

You need to create a function to retrieve the actual access level of the identified user.

On each form you need to show or hide the menus (if any) according to the user acces level. Also you may have to hide or disable some controls in the form.

IE: a reader user can see the info but can not modify it: The Save button should be hidden for this user.

Hope this helps

Thanks for your Guidence for above post by : lanitooot. But i hope lanitooot and definately wants to know HOW TO? can you help please.

If you could provide us some code or some url link where we can find and learn how to do?
TashiDuks

this is my code for a similiar program.

Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
    Dim ObjNextForm As New MainMenu
    Dim da As New SqlDataAdapter
    Dim ds As New DataSet
    Dim dt As New DataTable

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click

        Dim con As SqlConnection = New SqlConnection("server = VISIONSQL1;database = NCR1sql;Trusted_Connection = yes")
        Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM LOG_IN WHERE User_Name = '" & txtUsername.Text & "' AND User_Password = '" & txtpassword.Text & "' ", con)


        con.Open()
        da.SelectCommand = cmd
        da.Fill(ds, "LOG_IN")
        dt = ds.Tables("LOG_IN")

        Dim sdr As SqlDataReader = cmd.ExecuteReader()

        If (sdr.Read() = True) Then
            Username = txtUsername.Text
            Department = ds.Tables(0).Rows(0).Item("Dept").ToString
            Permission = ds.Tables(0).Rows(0).Item("Permissions").ToString
            Facility = ds.Tables(0).Rows(0).Item("Facility").ToString
            PermissionTwo = ds.Tables(0).Rows(0).Item("PermissionsTwo").ToString
            'MessageBox.Show("The user is valid!")

            'Pass verification and go to main form.

            ObjMenu = New MainMenu
            ObjMenu.Show()
            Me.Hide()
        Else
            MessageBox.Show("Invalid username or password!")

        End If
        con.Close()
    End Sub

End Class

I have a SQL database with fields: User_Name, User_Password, Dept, Facility, Permissions, PermissionsTwo.

so when I call up the log-in form it saves that information in my global variable in the MODULE.
This way you can use those permissions in whichever form you want to restrict.

Module Module1

    Public Password As String
    Public Username As String
    Public Department As String
    Public Permission As String

End Module

The code below shows how to use the permissions to go to the form or function you want.

Private Sub btnAdminNcrLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdminNcrLog.Click
        If Permission = "ADMIN" Or PermissionTwo = "ADMIN" Then
            ObjLogForm = New NcrLog
            ObjLogForm.Show()
        Else
            MsgBox("You are not authorized to Delete NCRs", vbCritical + vbOKOnly)
        End If
    End Sub

Thanks for your solution. If you want to have disabled menus and buttons as per the user class.. then how? Can you please tell me. If you can tell me where do i get a sample project for this solution.. i would be much gratefull...

to disable buttons per user class use the code below:

If Permission = "ADMIN" Or PermissionTwo = "ADMIN" Then           
Button1.Visible = False 'if you do not want the user using that particular button
Menu1.Visible = Fase
'what I mostly use is I put certain buttons in a groupbox then I make that groupbox visible depending on the permissions
Groupbox1.Visible = Fasle
        Else            
MsgBox("You are not authorized to Delete NCRs", vbCritical + vbOKOnly)        
End If

I would recommend not to hard write user names or passwords in your code, because if they change, you'll need to recompile your code. Instead get/save them from/to an external file or DB.

I also would recommend to encrypt this information.

I would also remember you that in order to know the name of who is the current logged user you can use the System.Environment.Username.

Hope this helps.

This article has been dead for over six months. Start a new discussion instead.