title: Saving modular user permissions in a database
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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).</p>
  
  <p>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.</p>
  
  <p>My brainstormed options so far:</p>
  
  <ol>
  <li>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.</li>
  <li>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".</li>
  <li>Create a separate table for user perms like so:</li>
  </ol>
  
  <pre>UserId  | Module  | Permission
  1       | A       | 1
  1       | B       | 0</pre>
  
  <p>What do you think?</p>