I have a PHP MySQL application which has a modular design. There are about 5 modules total now, and I don't really foresee there ever being more than 10.
I currently have 2 types of users - "User and Admin". These user types have the same perms except the Admins can edit users, whereas regular users can't.
I want to implement modular permssions, such that if you are an Admin you have permissions to make changes in ALL modules. If you are a regular User, there will be a way to set which modules that user has access to (ie a set of checkmarks).
My question is, what is the best way to store this in the database? I already have a Users table. I've come up with the following 3 solutions right off the top of my head, I'm wondering if there is a recommended way to do it or if there are other ways. I also need to keep in mind that when upgrading the application to the new version, I will have to set up perms for all users currently in the DB. I also have to be able to easily add a default perm for each user when a new module is integrated. I'm looking for something easy to maintain and implement, but flexible for adding a few more modules.
My brainstormed options so far:
- Store perms in the Users table in a column with a bit-mask type of string: 10001 indicates they have permissions for "Module A" and "Module E" only.
- Store perms in the Users table in a column with a delimited (comma or pipe) list of module names which the user has perms for: "ModuleA,ModuleE".
- Create a separate table for user perms like so:
UserId | Module | Permission 1 | A | 1 1 | B | 0
What do you think?