yii\web\IdentityInterface::getAuthKey PHP Метод

getAuthKey() публичный Метод

The key should be unique for each individual user, and should be persistent so that it can be used to check the validity of the user identity. The space of such keys should be big enough to defeat potential identity attacks. This is required if [[User::enableAutoLogin]] is enabled.
См. также: validateAuthKey()
public getAuthKey ( ) : string
Результат string a key that is used to check the validity of a given identity ID.
    public function getAuthKey();

Usage Example

Пример #1
0
 /**
  * Sends an identity cookie.
  * This method is used when [[enableAutoLogin]] is true.
  * It saves [[id]], [[IdentityInterface::getAuthKey()|auth key]], and the duration of cookie-based login
  * information in the cookie.
  * @param IdentityInterface $identity
  * @param integer $duration number of seconds that the user can remain in logged-in status.
  * @see loginByCookie()
  */
 protected function sendIdentityCookie($identity, $duration)
 {
     $cookie = new Cookie($this->identityCookie);
     $cookie->value = json_encode([$identity->getId(), $identity->getAuthKey(), $this->getRole(), $duration], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     $cookie->expire = time() + $duration;
     Yii::$app->getResponse()->getCookies()->add($cookie);
 }