Cakephp: How to authenticate user? - cakephp-3.0

I have user form with fields user name and password which stored in user table in one database
and one other database which have only user_id
I want to authenticate user_id
if user_id is match in both table then login

Related

How I can Make Schema for Tables (Client, Companies and Users)

I am developing a program in PHP and I need to create MYSQL Schema for the following tables
Users
Clients
Companies
My Requirements are
A Client may have many companies and a company must belong to a client
Client can be able to login into the application as a user
A Company may have many users and each user can to login to an application
There is a superuser, which does not belong to any client|company but still can be login into the application
To handle the login system, I introduced a table users and created the schema as given below
table: clients
id as PK
name
table: companies
company_id as PK
name
client_id as FK
table: users
id as PK
company_id as FK
client_id as FK
is this ok? the way I am created the schema.

how to show data in mysql depending to a user who logged in mysql and codeigniter?

how to limit the user can only CRUD his own data in a table. for example there are 2 users, namely user1 and user2 in table_user, each user has data in table_transaction. When user1 logs in, the data displayed is only data belonging to user1

Joining table in postgresql

I have a database that stores username and password. The table is logintable as shown in the picture.
similarly, I have a table called userdetails that stores the details of a particular user as shown here:
Now, using the query select * from .. in postgres, how do I retrieve all the details of a particular user when he signs in with his username and password ? I mean for different user different records needs to be retrieved.
You need a way to join logintable to userdetails. There should be a table that contains both username and firstname/lastname or other way to identify the user in userdetails. If you are making this schema yourself, consider just putting the username in userdetails.

how to update multiple records for single user in database table

I want to update multiple roles for user when admin update user roles
I have table as follow
user_roles
username || role_name
user1 | role1
user2 | role2
users
username || password
user1 | abc
now suppose admin updates username to guest as well as assign multiple roles lets say 5 roles(role1,role2,role3,role4,role5) then how to update table ?
do I need to first delete existing records from both tables ?
You don't need to delete existing records, you can simply use a SQL Update statement, see the below link for how it's done.
http://www.w3schools.com/sql/sql_update.asp

Database design for 2 types of users

I have 2 ways for users to create an account on my website.
a. Normal Registration Form (email, password)
b. Registration via Facebook Connect (fb_userid, email)
Which is the best practice to implement this using MySQL (InnoDB engine) ?
My approach:
[USER]
user_id
user_type (normal/facebook)
[USER_NORMAL]
user_normal_id
user_id
email
password
[USER_FACEBOOK]
user_facebook_id
user_id
email
fb_userid
What do you suggest?
This single table would be more simple (in my opinion):
user (user_id, user_email, user_password, user_fbid)
You don't need a "type" because you can use a CASE to determine if user_fbid is NULL then it's a "normal" account, else if user_password is NULL then it's a Facebook account.
I would have two tables.
One table should contain basic user information:
user (user_id, user_email, user_password)
The other table should be generic and link 3rd party accounts to these users. Example:
user_ext (type, user_id, uid)
The type field should contain the type of service (in this case Facebook), and the unique identifier for the service (in this case the Facebook User ID). It should then link back to the user_id.
This strategy will then allow you to add additional services that users can authenticate against in the future.
I would keep everything on one table and differenciate them by if they have a Facebook Id or not.
If those are the only fields then it's probably easiest to put all the fields in one table and have NULLs as appropriate.
However, if you want a normalised design you would go for something like this:
[USER]
user_id (PK)
email
(Other fields common to both)
[USER_NORMAL]
user_id (PK, FK to USER.user_id)
password
(Other fields specific to 'normal')
[USER_FACEBOOK]
user_id (PK, FK to USER.user_id)
fb_userid
(Other fields specific to FB)
If 'password' is the only field specific to 'normal' users and there are many fields specific to FB users then a compromise might be to have two tables: USER (as above but containing 'password') and USER_FACEBOOK
I would probably prefer to keep all users in 1 table. You can have fields that are null if that user's type doesn't have that field. For example fb_userid can be null if the user is normal.
[USER]
user_id
user_type (normal/facebook)
email
password
fb_userid (can be null: yess)