Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2: Why is the auth key in class User?

Tags:

php

yii

yii2

As the title clarifies why is the auth key introduced in Yii2? What're it's main usages and how it is useful in authentication?

like image 363
Ejaz Karim Avatar asked Oct 02 '14 18:10

Ejaz Karim


People also ask

How to login user in yii2?

To login a user, you may use the following code: // find a user identity with the specified username. // note that you may want to check the password if needed $identity = User::findOne(['username' => $username]); // logs in the user Yii::$app->user->login($identity);

What is the auth key?

Authkey is a Cross Channel Communication Platform which allows you to send Notifications using multiple channels at the same time for a certain Event for e.g. Sending Email & Voice for Order details, Voice for COD confirmation etc.

How does authentication work?

In authentication, the user or computer has to prove its identity to the server or client. Usually, authentication by a server entails the use of a user name and password. Other ways to authenticate can be through cards, retina scans, voice recognition, and fingerprints.


1 Answers

The main use is to authenticate the user by cookie. When you choose to be remembered at Login, this is how you are remembered. The system has to identify and login you somehow. It can either save your username and password in a cookie (that would be unsafe) or it can remember you by other means. This is one of the means. After you login into your Yii application take a look at the _identity cookie that it creates, You will see that the auth_key is part of the cookie.

The cookie actually remembers the $id the $authKey and the $duration, an id\auth_key combination is safer to remember then a username/password one.

like image 162
Mihai P. Avatar answered Sep 27 '22 16:09

Mihai P.