ARTICLE

Application Level Security System

Posted by Tajwer Jalal Articles | Security in VB.NET September 15, 2010
This article will provide help in developing Application Level Security System.
Download Files:
 
Reader Level:

Description

This is a common situation where one needs to restrict some user for accessing some menus and some operations like AddNew Record, Edit / Change Record, Delete Record etc. it is required for almost every application that runs in multi user environment.

To fulfill this task you need some tables to hold data and a form to manipulate that data according to your policy.

Follow the three steps given below to accomplish this task.

Step 1:

Create following tables in your database or in a new database.

Security1.gif

Security2.gif

Security3.gif

Security4.gif

Step 2 :

Make a form like given below (Codes attached)

Security5.gif

Step 3

Add following codes in your mdiForm's or Form contains menus Load events.

Public Sub LoadMenu()
Try
Dim
da As New SqlDataAdapter
Dim ds As New DataSet
Dim ds1 As New DataSet
Dim strSql As String
Dim nParentId As Integer
Dim i As Integer
Dim tsm As ToolStripMenuItem
 
For Each tsm In frmMain.MenuStrip.Items
strSql = "select Menus.MenuID,Menus.MenuName from UserRights " _
            & "Inner Join Menus On Menus.MenuID=UserRights.MenuID " _
           & "Where userID=" & intUserId & " And Menus.MenuName='" & tsm.Name.ToString & "' and            
                Menus.programid=" & intProgramID

da = New SqlDataAdapter(strSql, conSecurity)
ds.Tables.Clear()
ds = Nothing
ds = New DataSet
da.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
nParentId = ds.Tables(0).Rows(0).Item("Menuid")
tsm.Enabled = True
For  i = 0 To tsm.DropDown.Items.Count - 1
'MsgBox(tsm.DropDownItems(i).Text)
strSql = "select Menus.MenuID,Menus.MenuName from UserRights " _
& "Inner Join Menus On Menus.MenuID=UserRights.MenuID AND Menus.programid = UserRights.ProgramID " _
& " Where userID=" & intUserId & " And Menus.MenuName='" & tsm.DropDownItems(i).Name & "'"
da = New SqlDataAdapter(strSql, conSecurity)
ds1.Tables.Clear()
ds1 = Nothing
ds1 = New DataSet
da.Fill(ds1)
If ds1.Tables(0).Rows.Count > 0 Then
tsm.DropDownItems(i).Enabled = True
Else
tsm.DropDownItems(i).Enabled = False
End If
Next
Else
' tsm.Enabled = False
End If

Next

Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "Loading Menus")
End Try
End Sub


 

Login to add your contents and source code to this article
Article Extensions
Contents added by Peter Beasley on Aug 31, 2011
Looks perfect.  I downloaded and will try it.

Thanks very much - will save a lot of redundant effort
share this article :
post comment
 

Looks perfect.

Posted by Peter Beasley Aug 31, 2011

Can you tell me what about code INSET,SELECT,UPDATE,DELETE working with VB.Net and SQL server? or you can post source code?

Posted by seyha nasa Dec 30, 2010

Nice article tajwer, i am expecting more good articles form you.

Posted by Dinesh Beniwal Sep 23, 2010

Thanks Mahesh

Posted by Tajwer Jalal Sep 16, 2010

Keep up the good work.

Posted by Mahesh Chand Sep 16, 2010
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Diagram
Become a Sponsor