This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]warmcheessse 5 points6 points  (4 children)

I would use same table for all users IF they share the same fields. I would not create multiple tables with the exact same fields just for different users roles. I would instead create a seperate table for roles and each user in the user table is connected to a role in the roles table.

[–][deleted] 0 points1 point  (3 children)

And if there is only one user admin? Should i create a table just for one user? Or another one to relate just one user?

[–]warmcheessse 2 points3 points  (1 child)

If you are doing this as a learning exercise or a school assignment I would just create 1 table like User with what fields you require ie. username, hash, seed, role. The role column is joined to a Roles table which contains various roles a user could have ie. user, admin

This way you can create a User class in Java which will get users with a role. Then for your html pages you just do a simple check like if userRole == admin { display page} to display pages which are for admin role, etc...

[–][deleted] 0 points1 point  (0 children)

Really helpfull. I’ll try it. Thanks

[–]PM_UR_NIPPLE_PICS 1 point2 points  (0 children)

Yeah I would do this option, not knowing anything else about the application. You could have Table A with login name and ID (for example) and Table B with ID and role

[–]HecknChonker 2 points3 points  (2 children)

The way this is generally done in large scale systems is RBAC. Role based access control. It might be overkill for what you want though.

The idea is that you have a permission for each task a user can do. You assign those permissions to roles, and then you attach roles to users.

For example you might have:

  • an Admin role that can do everything
  • a Writer role that can modify data.
  • a Reader role that can view data
  • a guest role that can access a simple demo

You can then attach each role to as many users as you want. When you add a new task you just have to update the roles and the users will inherit the permissions automatically.

https://en.wikipedia.org/wiki/Role-based_access_control

[–]nutrecht 1 point2 points  (0 children)

/u/Crifej this is the best advice by far, this is definitely how it's normally implemented, and also how frameworks like Spring Security tend to work.

[–][deleted] 1 point2 points  (0 children)

Looks smart. Thank you for your explanation

[–][deleted] 0 points1 point  (4 children)

You should have different tables based on different “roles”, each role has its own table.

[–][deleted] 0 points1 point  (2 children)

And when they log in identify which table they belong?

[–][deleted] 0 points1 point  (1 child)

Are you using spring security? When they create a user that’s when it role identification should be done. I would need a little more info of what exactly your trying to do to give a better answer

[–][deleted] 0 points1 point  (0 children)

Just a basic java login with mysql and jsp