开发者

how to set up different levels of access in a vb.net application based on an SQL table of Usernames?

I want to make different levels of access for a vb.net program i'm writing. I have a database called "stratocast". I want to show a specific form for entries in this table with "IsManager" checked and another specific form for those with "IsAdmin" checked.

Im using MySql server and visual basic 2010 express

EDIT:

To clear up any misconceptions about my post, ill explain further:

In my vb.net application i have a login form with two textboxes; One for the usernam开发者_运维问答e and one for password. I also have three other forms, one is called "frmAdmin", another called "frmManager" and another one called "frmEmployee".

On my database i have a table called "employee" with columns called "name", "title", "IsManager", "IsAdmin", "Username" and "Password".


IsManager and IsAdmin are both Boolean columns

  • This means that their values can only be 0 or 1 and the result is displayed as a checkbox.

When the employee logs into this applcation i want it to check whether or not the employee is a manager, an administrator, or just a regular employee with no additional rights. If the employee is a manager, i want to show "frmManager". If the employee is an Administrator i want to show "frmAdmin". And if the employee has no additional rights then i want to show "frmEmployee".

I'd like to keep the configuration for access level checking confined to the one table but if it's better to have separate tables for each level of access (ie: tables called Admin,Manager, and Employee) then ill consider that too.

thanks!


Quick Update: http://www.vbmysql.com/articles/vbnet-mysql-tutorials/the-vbnet-mysql-tutorial-part-1

It seems you need a bit more information on how to work with databases, and how to ensure data integrity in a database. The above link is a 6 part series on working with Vb.NET and MySQL. I would suggest giving it a look over - it will answer most / all of your questions.


I'm a bit lost on what exactly you're trying to produce as an end result.

What I can see is you want to display a different form depending on if the employee is a manager or admin, and you probably want to display both of those forms if the employee is an Admin AND a manager.

So you have your SQL Query result. You don't need any logical if/then for that part as you're returning the data based on an employee ID (Please say you have a PK ID Field).

What I would do is have a group of controls that are hidden / visible depending on the permission of that employee.

Database Design;

Table: Employee
EmployeeID, int PK, not null
Name, varchar, null
Password, varchar, null
Title, varchar, null
IsManager, bit, null
IsAdmin, bit, null

**Are you using a Salt for your passwords / or any encryption? based on the pseudo code below I will do it as there is no encryption on the passwords, and let you deal with that.

You're databaes will have many employees in it. What you want to do is when one logs in is to check the username and the password field against your database.

  Select EmployeeID, Name, Title, IsManager, IsAdmin FROM employee Where Name = 'UserName' and Password = 'Password

Where 'Username','Password' are your variables that need to be passed in. example:

Select EmployeeID, Name, Title, IsManager, IsAdmin FROM employee Where Name = 'Ryan.Ternier' and Password = 'Trogdor'

This will return a user to you, with your IsAdmin and IsManager flags. If you have an Employee class, instantiate it, populate it, and return it to your presentation so it can do the forms (example below).

Public Sub SetForms(ByVal emp As Employee)
    If emp.IsManager Then
        Dim frm As New ManagerForm
        frm.Show()
    End If

    If emp.IsAdmin Then
        Dim frm As New AdminForm
        frm.Show()
    End If

    Dim frm As New EmployeeForm
    frm.Show()

End Sub

I would recommend getting that path done.

Login Form passes UserName/Password to your Login method, which returns an Employee. If Employee is not null/nothing great, if it's null/nothing then the credentials are wrong.


Based on your answers i'd rather recommend learning basic concepts of Visual Basic,SQL,Logins and such.

Here's one of a the books which is quite good for learning for beginners on these concepts. You'll get an overall image of how things are done.

The Book

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜