Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6696969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:24:15+00:00 2026-05-26T06:24:15+00:00

I am creating a user authentication library (for the exercise). One of the things

  • 0

I am creating a user authentication library (for the exercise).

One of the things I am adding is is, a user can be assigned to multiple roles.

Each role has set of permissions (think editUser, createUser etc).

If a user is part of two groups if any group has permission to do an action then the user can do the action.

I am wondering the best way to store this information from a mysql database point of view.

I was thinking

users            : ID            | username | etc  
groups           : ID            | name     | etc  
user_group       : group_ID      | user_ID  
permissions      : ID            | name     | description (lookup table)
group_permission : permission_ID | group_ID

and basically if a group has a permission then it gets an entry in group_permission.

My question is, is this the most productive way to do this, or would I be better to have each permission as a column in the groups table and drop the group_permission table?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:24:16+00:00Added an answer on May 26, 2026 at 6:24 am

    You approach looks nice and normalized, kudos for that.
    One thing that I’m missing is a non-permission table, i.e. a table that disallows actions.
    Active directory has this and this allows you to quickly block permissions to an object.

    This allows you to allow access to all accounts, except …..
    If you do it the other way round, you have to allow access to each object whilst leaving out the HR data.
    The first way sets permissions on 2 objects (1 permission on parent, 1 dismissal on child), the second way can run into dozens of permissions.

    Personally I would update the permissions table to also include exclusions.
    This would allow you to attach exclusions to both groups and users.

    Use a blackhole table to simplify addition of new permissions
    In order to simplify adding new permissions, you can create a new blackhole table.
    This does not store anything, but will fire a trigger instead that does the insertion for you, in this manner you can hide the fact that your DB is normalized from the insertion code.

    CREATE TABLE bh_permission (
      user_or_group_id unsiged integer not null,
      isuser ENUM('user','group') not null default 'user',
      permission_description varchar(255) not null,
      allow_or_not ENUM('allow','forbid') not null default 'allow'
    ) ENGINE = BLACKHOLE;
    

    Now you can insert into the table specifying either group or user_id

    INSERT INTO bh_permission VALUES ('123','group','p_HR_files_2011','forbid');
    

    And have a trigger to handle the technical details:

    DELIMITER $$
    
    CREATE TRIGGER ai_bh_permission_each AFTER INSERT ON bh_permission FOR EACH ROW
    BEGIN
      DECLARE Mypermission_id INTEGER;
      //like is always case-insensitive, `=` is not.
      SELECT p.id INTO Mypermission_id FROM permissions p 
        WHERE name LIKE NEW.permission_description LIMIT 1;
      IF isuser = 'user' THEN
        INSERT IGNORE INTO user_permission (user_id, permission_id, allow_or_not)
          VALUES (NEW.user_or_group_id, Mypermission_id, NEW.allow_or_not);
      ELSE
        INSERT IGNORE INTO group_permission (group_id, permission_id, allow_or_not)
          VALUES (NEW.user_or_group_id, Mypermission_id, NEW.allow_or_not);
      END IF;
    END $$
    
    DELIMITER ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a user control in C# and I am adding my own
I'm creating a user-based website. For each user, I'll need a few MySQL tables
I am creating a user input at one of the events: var throwConnectBox =
i am creating a MVC3 application where the user can be either an Admin
I am working on a Rails application that has user authentication which provides an
I'm creating a user authentication system for my site. I want to add a
Possible Duplicate: Bottle-friendly WSGI authentication library/middleware I'm creating a simple web application with Python
I understand the basic user authentication, login, creating accounts, extending user model... I am
I am creating my first web application and want to setup a user authentication
I'm creating (really, re-creating) an app that has existing user and other data in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.