Question Locked

Grant Access rights to users based on who logged in (vb 2005)

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

hi,i have created a vb 2005 application that has a log in form where user put username and password to be able to log in.
In the back end i have created a sql database with the users table with username and password fields such that only users that exits in the DB will be able to log in.So far I have achieved this.

What I want to do now is grant access to different menu items depending on which user is currently logged in. I have added another field in the users table called usergroup which stores the group a particular user belongs to, the group assignement can be performed when creating the user from the application.
I need help how can i achieve this in vb(.net 2005)
looking forward to hear from u guys

godfrey

2 replies

by jazzygodfrey

I got it!! something like this

Public Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim UserGroup As String
Dim UserName As String = txtUsername.Text
Dim password As String = txtPassword.Text

Dim SelectString As SqlCommand = New
SqlCommand("SELECT * FROM tblUsers where UserName='" & UserName & "'", objConnection)

SelectString.Connection = objConnection

objConnection.Open()
SelectString.ExecuteNonQuery()
objConnection.close()

If UserGroup = "File Creator" Then

Menu_Form.Show()
My.Forms.Menu_Form.mnuCreateUser.Enabled = False
My.Forms.Menu_Form.mnuOpenFiles.Enabled = True

ElseIf UserGroup = "Admin" Then

My.Forms.Menu_Form.mnuCreateUser.Enabled = True
My.Forms.Menu_Form.mnuOpenFiles.Enabled = True
ElseIf UserGroup = "Standard User" Then

My.Forms.Menu_Form.mnuCreateUser.Enabled = False
My.Forms.Menu_Form.mnuOpenFiles.Enabled = True
Else

MessageBox.Show("This account has no credentials to log In", "Log In", MessageBoxButtons.OK, MessageBoxIcon.Information)

end if
End Sub

This discussion is closed to new replies.