What is the recommended way to handle different user roles in a C # application?

I am going to make a small business application that will be used locally to scan and store documents in a database located on a local computer or on a computer located on the same local network.

I could create a table called "Users with username and password" and show a form or another form according to the usertype identifier. But I'm more interested in the recommended approach of experienced programmers.

Any tips?

Edit: I'm looking for something that will be safe enough, but also extensible enough.

+3
source share
5 answers

If this is a simple application, do not use the spaceship to cross the road.

Create the following database schema:

Users : username and hashed password

Roles : RoleName, RoleID, RoleStrength (int)

RolesMembership : A Rolemembership table containing a userid and roleid to enable multiple future memberships.

When setting up roles, give them a numerical weight. i.e.: Admins = 1000, Power-users = 500, guest = 10. Thus, in your forms, you can say that if the user level is 500 or higher, set to full view, otherwise view or lack of access.

Even better, abstract it with the security class using methods like IsPowerUser or IsAdmin.

, .

+1

"", , .

, , , . , .

, , , , .

, , . .

+1

"" , .

. -.

, .

0

Visual Studio, . . .

0

Source: https://habr.com/ru/post/1748887/


All Articles