I am going to be making a small user system but I have questions.
-
If I were to make a registration table (mysql), what is wrong with just storing the password and username into the database without encryption?
-
I am trying to think of how to build the admin portion. Should I just check a column in the database to see if user is admin or not? If true, then admin page will be revealed.
-
For admin powers, let’s say I have 3 powers: delete user, approve user, and move user. In a few scenarios, I may want to give some people only the ability to approve, or delete, or all, or any combination. How would I make this? I was thinking of having a column for each power and have the script check each column. Let’s assume I have over 20 powers that will be added.
-
If I have a website where people can create groups and become admins of their groups and the these admins can give different combination of admin powers to people in their group (For ex, Zack creates and group called Mountain and grants one member the ability approve new group members and grants a second member the ability to delete members and assigns a third member the ability to delete and approve. How will I structure this in MySQL? Should I use a columns that say what group are they admin of and what ability do they have? E.g. columns: Delete, Approve, GroupMemberOf, GroupAdminOf and use checks.
I have an idea but I want to learn the more sophisticated ways.
Thanks for the answers so far, however, I am really looking for ideas on a structure ( Question 2 – 4 ). Please let me know if I can help clear up the question.
2 – 4. Use a table for access levels (1: member, 2: moderator (approval), 3: admin), and use yet another different table for user permissions where you store many-to-many connections like this:
In your case, user 1 is admin for the whole site, user 2 is admin for group 3 and moderator for group 2, user 3 is member of group 2.
[EDIT:]
Some more thoughts on restricting powers for the different roles: Depending on your setup you should use some role enforcement on a per-page basis, e.g. in an MVC framework, I would extend the base controller to require a (role) authorization function that has to be called for each method, otherwise it should throw an exception. Methods (pages) that do not require the user to log in can use a dummy authorization.
So the authorization class will look like
Your new base controller class will look like this:
And finally in the end your controllers will look like:
[EDIT2:]
If you are not familiar with OOP, then you can do the following:
Here is a sample layout for a roles table:
You can then make a function authorize() to include in all your files:
In your files include this function and do the following