public function testSerialize() { $model = new AuthenticationAttempt(); $model->setIp('127.0.0.1'); $model->increaseAttemptCount(); list($id, $latest, $range) = [$model->getId(), $model->getLatestFailedAttemptTime(), $model->getLastFailedAttemptTimesInRange()]; $serialized = serialize($model); $new = unserialize($serialized); $this->assertSame($id, $new->getId()); $this->assertSame('127.0.0.1', $new->getIp()); $this->assertEquals($latest, $new->getLatestFailedAttemptTime()); }
/** * Adds one ip of a failed authentication unless its authentication succeeded previously (users may mistype some times). * * @param string $ip * * @return $this */ public function addFailedAuthenticationWithIp($ip) { if (!$this->isKnownIp($ip)) { if ($attempt = $this->getAuthAttemptModelByIp($ip, self::FAILED_AUTH_POOL)) { $attempt->increaseAttemptCount(); } else { $attempt = new AuthenticationAttempt(); $attempt->setIp($ip); $attempt->increaseAttemptCount(); $this->failedAuthentications->add($attempt); } } return $this; }