/** * Authenticate Credentials and generate token * @param $credentials * @param $identify * @return bool */ public function attempt($credentials, $identify = 'email') { $identifyVal = isset($credentials[$identify]) ? $credentials[$identify] : null; /** @var Collection $user */ $user = User::where($identify, '=', $identifyVal)->get(); if ($user->isEmpty()) { return false; } /** @var User $user */ $user = $user->first(); if (!\Hash::check($credentials['password'], $user->password)) { return false; } $uid = $user->{$this->getIdentify()}; /** Remember Token */ $remember_token = $this->generateRememberToken($uid); /** End */ $payload = new Payload($uid, time() + $this->getTtl(), null, null, null, $remember_token); $payload->generateSalt($this->getSecret()); return $this->toToken($payload); }
/** * Convert from token to data * @param $token * @return bool */ public function load($token) { $parts = explode('.', $token); if (count($parts) != 3) { return false; } $payloadArr = json_decode(base64_decode($parts[1]), true); /** Load Header and Encoder Instance */ $this->setHeader(json_decode(base64_decode($parts[0]), true)); $this->setEncoder($this->getEncoderInstance()); /** End */ $this->setPayload(Payload::getInstance($payloadArr)); $this->setSignature(base64_decode($parts[2])); return $this; }