|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
VBulletin permissions
I am experimenting with different ways to give permissions to do certain tasks on a web site I'm working on. I'm not satisfied with what I have come up with so far. I am looking at a VBulletin database and and confused on the concept of how the permissions work. I see they have multiple tables and use numbers, (i.e. 6458778). Do any of you know how they are doing this?
JMH
__________________
jmurrayhead Did I help you out? Make me popular by clicking the icon!New Members:Proper way to post a question Powered by ASP.Net |
|
#2
|
||||
|
||||
|
those numbers are most probably "bit-masks" - for example let's assume there
are 8 different permissions. we will work with string having 8 characters of 1 or 0, where 1 means the user has permission in the specific location and 0 means user does not have permission. for example, "00000000" means no permission at all, and "11111111" means full permissions. now take this 8 character string and treat it as binary number - convert it back to decimal and you get ordinary number that represents the user's permissions. for example, John Doe has permission over page1 and page5. the binary number would be: "10001000" or in decimal, 136 - and that's what you store in the database. quite hard to grasp, but once you do understand the concept, it's kind of amazing what you can do with this. ![]() |
|
#3
|
|||
|
|||
|
Quote:
That's awesome, thanks for that great explanation! I think I would like to try something like that out if I can figure out how to work it. Maybe I shall have to call on you again when I begin this, if you don't mind ![]() |
|
#4
|
||||
|
||||
|
no problem, I'm at your service!
![]() best approach would be to start slowly by trial and error. |
|
#5
|
|||
|
|||
|
Quote:
Excellent, I appreciate it! Well, I'll give you some info about what I'm trying to do and we can go from there. Let's say I have 6 sections of my site I want to create groups for. One of these sections is for administrators only. The other 5 give the "moderators", if you will, the option to add a record, (users may edit and delete records they add), edit records, (users may edit records others have added), and/or delete records, (users may delete records others have added). I want to be able to add users to multiple groups. The other ways I was doing it made that difficult, because if a user was a member of two groups, sessions would be set for the first group, and then overwritted with the permissions of the last group. Of course there are ways around this, but I think the way VBulletin does it would be easier for me to manage. Okay, so I think the first step would be to get the database set up to do this. I am using MySQL. Any suggestions on how I should set up for this system to work? Thanks again, JMH P.S. Feel free to move this to a more appropriate forum if need be. Perhaps users looking for similar solutions will not search the lounge for a particular problem like this ![]() |
|
#6
|
|||||
|
|||||
|
as I mentioned before, have one single numeric field for the permissions.
now suppose user JMH is member of 3 groups: 1, 3 and 5. to build the number that represent his permissions follow those steps: 1. build "bit mask" string: "10101" (1st, 3rd and 5th digits are 1) 2. use BinaryToInt() function (see below) to convert your bit mask string to integer 3. you will get 21 - store this as the permissions. and the opposite direction, when you read the number from database follow those steps to see if the member is part of specific group: 1. use IntToBinary() function (see below) to convert 21 back to "10101" 2. use such code for example to see if member is part of the 2nd group: Code:
If Mid(strBinaryPermission, 2, 1)="1" Then 'user is part of group 2! End If once you put it all in functions and add your own remarks I believe you'll see its power and advantages. ![]() and to save you some time, here are two helper functions: ASP Code:
I won't move this yet as it's not really language-specific... the codes can be converted easily to any language. ![]() Last edited by Shadow Wizard : December 27th, 2005 at 04:42 AM. |
|
#7
|
|||
|
|||
|
wow...maybe I should just stick to pc repair...lol Well, I am going to attempt to understand what the heck is going on in those functions. I understand that one is converting from binary to integer and another is converting from integer to binary. But the individual parts of the function I don't understand. I know what len does, but other's I've never seen before or never had to use. Perhaps you can enlighten me, I won't understand any of this unless I understand all of it, if you know what I mean.
First, copy: Copy(strBinaryPermission, 2, 1) What is going on here, I understand it's searching the string for a value. Second, ByVal: IntToBinary(ByVal num) I have no clue what's going on here. Third, Fix: num = Fix(num/2) All I know about fix is that it chops off the decimal point and integers to right of it. Or if you just feel like giving me a rundown of what is happening in each line, that would be cool too I tried looking up some of these, but descriptions of what they do were vague.Thanks for you help Shadow! |
|
#8
|
|||
|
|||
|
Wow. I guess what your trying to decipher from Shadow is security permissions and in awe of his execellent replication of binary control procedures you might try the security stucture layer.
This is an excellent concept that derives the persons level of admission dependant on the value entered, E.G. Full Permissions = 5 Administartor = 4 Top Level User = 3 Mid Level User = 2 Bpottom Level User = 1 Newbie = 0 When the user registars with your site they are given the specific security level to which they are credited. This number may be held in the username or even relational table as you decide. Hence the non-binary conformisist structure of allowing access into a site. From login you could access the table and determine access and control the viewing privileges of all users to your site. |
|
#9
|
|||
|