简体   繁体   中英

Approach to store user login and password on database when there are some roles totally different

I am creating site and there are 3 roles on it. Administrator, Teacher, Parent. User with any role has access to site, but 1 role has full access, teachers can only put marks for students, parents can only watch these marks. I understand how to separate roles into scripts. Just save some parameter depending on what database would return when I check login and password.

So! Administrator has only login name and username . Also it is possible to store information about how to contact the user to make system more user-friendly. That's all.

Teacher has firstname, lastname, midname (father's name), address, phone etc. And it must have login and password fields...

Parent has Firstname, Lastname, Midname only. And sure somewhere I should to store data about login and password.

So should I just check this tables 1 by 1 and depending on table I will find $login and $password I inputted in I will return role? I don't think it is a nice idea. Suggest something else please.

What I think to do. I think that it would be not very bad idea if I will create 1 more table like users where I will store: id, username, login, role, user_id (need to think about it). The problem is user_id. How exactly this table will be connected to others? For example user_id` would be 1. 101% there would be 1 row with such id.

I want to ask about exprience of your self-build systems. May you suggest something please!

You're right. It doesn't make sense to have different tables for users. I would recommend you to store authorization and personal data in separate tables. And of course you'll need additional table for roles:

简单的用户存储

The idea behind this scheme is to keep thin users table for fast authorization. If authorization was successful, than you should check permissions from roles or get personal data from user_data tables.

Look at this sql-fiddle for DDL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM