public function testSetAttemptLimit() { $a = new Auth(new File(__DIR__ . '/../tmp/access.txt')); $a->setAttempts(5); $a->setAttemptLimit(3); $a->authenticate('testuser1', '12test34'); $this->assertEquals(Auth::ATTEMPTS_EXCEEDED, $a->getResult()); $this->assertEquals('The allowed login attempts (3) have been exceeded.', $a->getResultMessage()); $this->assertEquals(6, $a->getAttempts()); $this->assertEquals(3, $a->getValidator('attempts')->getValue()); $a->setAttemptLimit(); $this->assertEquals(null, $a->getValidator('attempts')); }
<?php require_once '../../bootstrap.php'; use Pop\Auth; try { // Set the username and password $username = '******'; $password = '******'; // Create auth object $auth = new Auth\Auth(new Auth\Adapter\File('../assets/files/access-crypt.txt'), Auth\Auth::ENCRYPT_CRYPT); // Define some other auth parameters and authenticate the user $auth->setAttemptLimit(3)->setAttempts(2)->setAllowedIps('127.0.0.1')->authenticate($username, $password); echo $auth->getResultMessage() . '<br /> ' . PHP_EOL; // Check if the auth attempt is valid if ($auth->isValid()) { // The user is valid so do top-secret stuff } } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL . PHP_EOL; }