TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-08-2008, 04:44 PM   #1 (permalink)
The Addict
Top Contributor Good Samaritan 
 
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
RobertK is on a distinguished road
Help User rights management (binary rights aggregation)

I'm coding my own project on the sidelines, much like everyone else. But I intend to have a user rights system with a per-user override. Math isn't my strong suit, but especially not the binary sort! I'm halfway decent with it.

Here is the basic structure of the user table and user_class tables; what I want to do is pull the rights of the class, add any overrides, and exclude any rights forbidden.
Code:
  _users
    id       = int64
    ...misc details
    class    = int32
    exc_mask = int64
    inc_mask = int64

  _user_classes
    class_id = int32
    name     = text (max 255)
    rights   = int64
Now, I know I can OR the inclusion mask with the class rights to get the full rights given. But how do I exclude the rights? I know I can do XOR, but that isn't wise. If the permission isn't set, excluding with XOR will grant the right I wish to revoke.

One way may be AND NOT the mask for the exclusions (bits in the exclusion mask that are TRUE will be excluded) but I cannot remember if this is the correct operator.

So as you can see, I'm stuck trying to remember. I'm just writing the specifications right now, and I want to follow up with essential query parts. So I'd like to make note of which operations are significant to this, as well as if they can be done in the SQL query itself. Like (100% pseudocode, don't use this folks!):
Code:
SELECT (rights OR inc_mask AND NOT exc_mask) as 'rights' from myTable where yadda=yadda;
Thanks for the help in advance.

Edit:

I asked my Dad, who knows a great deal of binary things, and he says the process is what I thought. In PHP this would be:
PHP Code:
$rights = ($baseRights $incMask) & ~$excMask
Can anyone tell me if I can translate this into a MySQL query? I cannot seem to find data for binary functions in selections.

Edit2:

Well, it appears that the operands are exactly the same in MySQL, fortunately! I think I've solved my own question. I'll write up an article on this subject when I get it implemented.
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook

Last edited by RobertK : 01-08-2008 at 05:12 PM. Reason: Further info
RobertK is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:22 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design