protected function loginWithCookie()
    {
        $username = $this->request->getCookie('login.username');
        $password = $this->request->getCookie('login.password');

        //Checks if the cookies exist
        if (!$username || !$password) {
            return;
        }

        //Tries to login
        $this->request = $this->request->withParsedBody(compact('username', 'password'));
        $user = $this->Auth->identify();
        if (!$user || !$user['active'] || $user['banned']) {
            return $this->buildLogout();
        }

        $this->Auth->setUser($user);
        $this->LoginRecorder->setConfig('user', $user['id'])->write();

        return $this->redirect($this->Auth->redirectUrl());
    }