Asp.net permission management analysis

Source: Internet
Author: User

Permission management is generally divided into "User Management", "role management", and "permission management ". The permission management mainly controls how to add, modify, and delete a module. For example, a user can add Article ", But does not have the permission to modify (Review) the article. The following describes "permission management ".

First, check the format of the data stored in the database:CopyCodeCode: News: 3, Gallery: 1, users: 15

You may often see the format 3, 1, and 15 stored in the database, without the previous news, gallery, and users.ProgramIt is easy to view when writing. News stands for the News Module, gallery stands for the image library module, and users stands for the user management module, whereas 3,1, 15:Copy codeThe Code is as follows: 1 = 1 = 20
3 = 1 + 2 = 20 + 21
15 = 1 + 2 + 4 + 8 = 20 + 21 + 22 + 23

All these values can be obtained using bitwise OR:Copy codeThe Code is as follows: 1 = convert. toint32 (1)
3 = convert. toint32 (1 | 2)
15 = convert. toint32 (1 | 2 | 4 | 8)

And 1, 2, 4, and 8 correspond to the permission enumeration:Copy codeThe Code is as follows: // <summary>
/// 1 add, 2 modify, 4 Delete, 8 manage list
/// </Summary>
Public Enum perm
{
Add = 1,
Update = 2,
Delete = 4,
Readlist = 8
}

If you already have a permission value of 7, how do we know what permissions this user has? Our analysis:Copy codeThe Code is as follows: 7 = 1 + 2 + 4 = 20 + 21 + 22 = 2 3-1

In fact, this is a mathematical formula. I'm glad that what I learned in the Mathematics Department has a role in programming:Copy codeThe Code is as follows: sigma (2n, n is a natural number) = 2n + 1-1, namely 1 + 2 + 4 + 8 +... + 64 = 128-1 = 127

Undoubtedly, this is complicated.
Unfinished, To be continued...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.