简体   繁体   中英

User Login System Database Schema…Please critique?

I am creating a user login system for my website and I need some help creating the database. So I far I have these 3 tables. Do you think this is a proper database schema? If not, then what would you suggest?

---Users---
user_id
user_name
user_email
user_firstname
user_lastname
user_state
user_country
user_occupation
user_dob
user_accountcreationdate
user_sex
user_role
user_password

---Roles---
role_id
role_name
role_description

---Logins----
user_id
last_login
browser_type
ip_address

Edit**** Would this be correct then? I added in the 4th table for User Roles. If I add the 4th table does that mean I can remove user_role from the Users table?

---Users---
user_id
user_name
user_email
user_firstname
user_lastname
user_state
user_country
user_occupation
user_dob
user_accountcreationdate
user_sex
user_role
user_password

---Roles---
role_id
role_name
role_description

---Logins----
user_id
last_login
browser_type
ip_address

---User Roles---
user_id
role_id

Your schema shows that each user will only have one role. You'll probably discover quickly that you want to do it more granularly than that. I would suggest having a user_role table that maps user_id to role_id (along with date_granted, date_revoked, granted_by, etc).

If you wanted to be really normalized, users.occupation would be a foreign key to an occupations table. state and country , too.

Be very careful how you store the password.

If you're logging successful logins, why not log unsuccessful ones, too. That might give you an indication of someone who needs help or whose account is being hacked.

Good luck.

Ya It's looking good.. But Why Not Active Flag To Activate/Deactivate Users. And Only Allowing Them to login after they verified their email identity by unique link or OTP .

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