开发者

Multiple Authentication methods, or implement role based Authentication?

开发者 https://www.devze.com 2022-12-15 12:06 出处:网络
I have a prob开发者_JS百科lem I am trying to solve as smooth as possible, and also keep it as safe and flexible as possible!

I have a prob开发者_JS百科lem I am trying to solve as smooth as possible, and also keep it as safe and flexible as possible!

I have a web app where I have 2 kinds of users; Back end users (trusted users; Admins!), and Customers (Front end users; not trusted in the same way)! They do work on some of the same data in the database, but the Customers can only do a subset of what the Back end users can do (like Salesforce users and customers "Self Service Portal")!

I also want to have 2 separate tables in the database for the back end users and the customers (tables are named User and Customer, and they both have a username and password row)...

Should I implement this with 2 different authentication methods, or should I use one authentication method and use roles instead (Then I would skip having 2 tables I the database with username and password, and let all use the User table)?


The following database structure would allow for scaling if you find that you need to eventually maintain multiple roles for users (which happens alot from my experience).

CREATE TABLE user (
   id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
   name VARCHAR(120),
   created_ts DATETIME DEFAULT '0000-00-00 00:00:00'
);

CREATE TABLE user_role (
  id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  user_id INT(11) UNSIGNED NOT NULL,
  role_id INT(11) UNSIGNED NOT NULL 
);

CREATE TABLE role (
  id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(125)
);


I would suggest you use one table and just setup roles. If properly done this will be easier to maintain. Of course this is the case if they have common fields such as name, surname.

0

精彩评论

暂无评论...
验证码 换一张
取 消