src/Web/User.php
protected function getIdentityAndDurationFromCookie()
    {
        $value = $this->request->getCookies()->getValue($this->identityCookie['name']);
        if ($value === null) {
            return reject(null);
        }
        $data = json_decode($value, true);
        if (is_array($data) && count($data) == 3) {
            list($id, $authKey, $duration) = $data;
            /* @var $class IdentityInterface */
            $class = $this->identityClass;
            return $class::findIdentity($id)
                ->then(null, function($error) {
                    $this->removeIdentityCookie();
                    return reject($error);
                })->then(function($identity) use ($id, $authKey, $class, $duration) {
                    if (!$identity instanceof IdentityInterface) {
                        throw new InvalidValueException("$class::findIdentity() must return an object implementing IdentityInterface.");
                    } elseif (!$identity->validateAuthKey($authKey)) {
                        Reaction::warning("Invalid auth key attempted for user '$id': $authKey");
                        throw new InvalidValueException("Invalid auth key attempted for user '$id': $authKey");
                    } else {
                        return ['identity' => $identity, 'duration' => $duration];
                    }
                });
        }
        $this->removeIdentityCookie();
        return reject(null);
    }
protected function getIdentityAndDurationFromCookie()
    {
        $value = $this->request->getCookies()->getValue($this->identityCookie['name']);
        if ($value === null) {
            return reject(null);
        }
        $data = json_decode($value, true);
        if (is_array($data) && count($data) == 3) {
            list($id, $authKey, $duration) = $data;
            /* @var $class IdentityInterface */
            $class = $this->identityClass;
            return $class::findIdentity($id)
                ->then(null, function($error) {
                    $this->removeIdentityCookie();
                    return reject($error);
                })->then(function($identity) use ($id, $authKey, $class, $duration) {
                    if (!$identity instanceof IdentityInterface) {
                        throw new InvalidValueException("$class::findIdentity() must return an object implementing IdentityInterface.");
                    } elseif (!$identity->validateAuthKey($authKey)) {
                        Reaction::warning("Invalid auth key attempted for user '$id': $authKey");
                        throw new InvalidValueException("Invalid auth key attempted for user '$id': $authKey");
                    } else {
                        return ['identity' => $identity, 'duration' => $duration];
                    }
                });
        }
        $this->removeIdentityCookie();
        return reject(null);
    }
Determines if an identity cookie has a valid format and contains a valid auth key.
This method is used when [[enableAutoLogin]] is true.
This method attempts to authenticate a user using the information in the identity cookie.
@return ExtendedPromiseInterface with array|null Returns an array of 'identity' and 'duration' if valid, otherwise null.
@see loginByCookie()