Numeric Levels

In attempts to centralize my user database for most of my projects, I came across the problem of having different access levels.

If one level were higher then the other, the solution would be easy and a level four could be considered higher then a level three. Level four would have access to all of level three and some addition. However, I wanted to mix and match access levels. Instead of choosing to do something of the nature using comma or some other from of splitting different access levels and storing them I chose to do the following:

I chose to use a set of numbers by with the sum of any two terms (or any number or terms) couldn’t be reached in means other then the desired access levels. The series of numbers I used were:

1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, etc.

Each term was double the preceding term and those were assigned to different services.

Suppose that Bob has access to service #1, #3 but only those two. His access level would be the sum of the numbers assigned to each of those services (1+4 = 5). Then when wanting to check what services the user Bob has access to working backwards leads quickly to service #1 and #3 since there is no other method of reaching the sum of 5, using the series of numbers I’ve listed above.

Suppose that Bob has access level was 1280 it concludes that he has access to the services assigned numbers 1024 and 256 because only those two numbers will add up to 1280 out of the series.

Suppose that Bob has access level 32 then it would mean that he only has access to the service assigned to number 32 because even if you were to add up all the preceding terms the sum would come out to be 31.

I find that it works better and is easier to administrate then choosing to do something where access levels are seperated by slashes.

# August 5th, 2003 @ 1:36am in