Browse Source

added ability for accurate login errors

v3-dev
REJack 6 years ago
parent
commit
a1e7655d60
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 6
      app/Config/Aauth.php
  2. 17
      app/Libraries/Aauth.php
  3. 18
      tests/Aauth/Libraries/Aauth/LoginTest.php

6
app/Config/Aauth.php

@ -148,6 +148,11 @@ class Aauth extends BaseConfig
| Enables the DDoS Protection, user will be banned temporary when he exceed the login 'try' | Enables the DDoS Protection, user will be banned temporary when he exceed the login 'try'
| (default: true) | (default: true)
| |
| 'loginAccurateErrors'
|
| Enables unified error message (loginFailedAll vs loginFailedEmail/loginFailedUsername)
| (default: false)
|
| 'loginAttemptLimit' | 'loginAttemptLimit'
| |
| Login attempts limit | Login attempts limit
@ -173,6 +178,7 @@ class Aauth extends BaseConfig
public $loginSingleMode = false; public $loginSingleMode = false;
public $loginUseUsername = false; public $loginUseUsername = false;
public $loginProtection = true; public $loginProtection = true;
public $loginAccurateErrors = false;
public $loginAttemptLimit = 10; public $loginAttemptLimit = 10;
public $loginAttemptCookie = false; public $loginAttemptCookie = false;
public $loginAttemptLimitTimePeriod = '5 minutes'; public $loginAttemptLimitTimePeriod = '5 minutes';

17
app/Libraries/Aauth.php

@ -386,8 +386,21 @@ class Aauth
} }
else else
{ {
$this->error(lang('Aauth.loginFailedAll')); if ($this->config->loginAccurateErrors)
{
if ($this->config->loginUseUsername)
{
$this->error(lang('Aauth.loginFailedUsername'));
}
else
{
$this->error(lang('Aauth.loginFailedEmail'));
}
}
else
{
$this->error(lang('Aauth.loginFailedAll'));
}
return false; return false;
} }
} }

18
tests/Aauth/Libraries/Aauth/LoginTest.php

@ -91,6 +91,16 @@ class LoginTest extends CIDatabaseTestCase
$this->assertFalse($this->library->login('admin', 'passwor')); $this->assertFalse($this->library->login('admin', 'passwor'));
$this->assertEquals(lang('Aauth.loginFailedUsername'), $this->library->getErrorsArray()[0]); $this->assertEquals(lang('Aauth.loginFailedUsername'), $this->library->getErrorsArray()[0]);
$this->library->clearErrors();
$this->assertFalse($this->library->login('admin', 'password1234'));
$this->assertEquals(lang('Aauth.loginFailedAll'), $this->library->getErrorsArray()[0]);
$config->loginAccurateErrors = true;
$this->library = new Aauth($config, $session);
$this->library->clearErrors();
$this->assertFalse($this->library->login('admin', 'password1234'));
$this->assertEquals(lang('Aauth.loginFailedUsername'), $this->library->getErrorsArray()[0]);
$this->library->clearErrors(); $this->library->clearErrors();
$this->assertFalse($this->library->login('user99', 'password123456')); $this->assertFalse($this->library->login('user99', 'password123456'));
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); $this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]);
@ -110,6 +120,14 @@ class LoginTest extends CIDatabaseTestCase
$this->assertFalse($this->library->login('admina@example.com', 'password123456')); $this->assertFalse($this->library->login('admina@example.com', 'password123456'));
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); $this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]);
$config = new AauthConfig();
$config->loginAccurateErrors = true;
$this->library = new Aauth($config, $session);
$this->library->clearErrors();
$this->assertFalse($this->library->login('admin@example.com', 'password1234567'));
$this->assertEquals(lang('Aauth.loginFailedEmail'), $this->library->getErrorsArray()[0]);
$this->library = new Aauth(null, $session);
$this->library->clearErrors(); $this->library->clearErrors();
$this->assertFalse($this->library->login('admin@example.com', 'password1234567')); $this->assertFalse($this->library->login('admin@example.com', 'password1234567'));
$this->assertEquals(lang('Aauth.loginFailedAll'), $this->library->getErrorsArray()[0]); $this->assertEquals(lang('Aauth.loginFailedAll'), $this->library->getErrorsArray()[0]);

Loading…
Cancel
Save