diff --git a/app/Config/Aauth.php b/app/Config/Aauth.php index 1c745f5..c4e30fe 100644 --- a/app/Config/Aauth.php +++ b/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' | (default: true) | + | 'loginAccurateErrors' + | + | Enables unified error message (loginFailedAll vs loginFailedEmail/loginFailedUsername) + | (default: false) + | | 'loginAttemptLimit' | | Login attempts limit @@ -173,6 +178,7 @@ class Aauth extends BaseConfig public $loginSingleMode = false; public $loginUseUsername = false; public $loginProtection = true; + public $loginAccurateErrors = false; public $loginAttemptLimit = 10; public $loginAttemptCookie = false; public $loginAttemptLimitTimePeriod = '5 minutes'; diff --git a/app/Libraries/Aauth.php b/app/Libraries/Aauth.php index 668814e..3d0b39a 100644 --- a/app/Libraries/Aauth.php +++ b/app/Libraries/Aauth.php @@ -386,8 +386,21 @@ class Aauth } 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; } } diff --git a/tests/Aauth/Libraries/Aauth/LoginTest.php b/tests/Aauth/Libraries/Aauth/LoginTest.php index 7fdc185..23b0cd5 100644 --- a/tests/Aauth/Libraries/Aauth/LoginTest.php +++ b/tests/Aauth/Libraries/Aauth/LoginTest.php @@ -91,6 +91,16 @@ class LoginTest extends CIDatabaseTestCase $this->assertFalse($this->library->login('admin', 'passwor')); $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->assertFalse($this->library->login('user99', 'password123456')); $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->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->assertFalse($this->library->login('admin@example.com', 'password1234567')); $this->assertEquals(lang('Aauth.loginFailedAll'), $this->library->getErrorsArray()[0]);