Browse Source

enhanced loginAttemptCookie

- updated Config/Aauth
- updated Libraries/Aauth
- updated LoginAttemptModel
- updated CodeIgniter version in .gitlab-ci.yml & .travis.yml
v3-dev
REJack 6 years ago
parent
commit
bfac5ad95e
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 2
      .gitlab-ci.yml
  2. 2
      .travis.yml
  3. 1
      app/Config/Aauth.php
  4. 2
      app/Libraries/Aauth.php
  5. 56
      app/Models/Aauth/LoginAttemptModel.php

2
.gitlab-ci.yml

@ -20,7 +20,7 @@ variables:
# Configure mysql environment variables (https://hub.docker.com/r/_/mysql/) # Configure mysql environment variables (https://hub.docker.com/r/_/mysql/)
MYSQL_DATABASE: aauth_v3_ci4_testing MYSQL_DATABASE: aauth_v3_ci4_testing
MYSQL_ROOT_PASSWORD: root MYSQL_ROOT_PASSWORD: root
CODEIGNITER_VERSION: 'v4.0.0-alpha.4' CODEIGNITER_VERSION: 'v4.0.0-beta.1'
# Run our tests # Run our tests
# If Xdebug was installed you can generate a coverage report and see code coverage metrics. # If Xdebug was installed you can generate a coverage report and see code coverage metrics.

2
.travis.yml

@ -33,7 +33,7 @@ before_install:
before_script: before_script:
- echo 'extension = memcached.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - echo 'extension = memcached.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- shopt -s extglob dotglob && mkdir aauth_temp && mv !(aauth_temp) aauth_temp - shopt -s extglob dotglob && mkdir aauth_temp && mv !(aauth_temp) aauth_temp
- git clone https://github.com/codeigniter4/CodeIgniter4.git CodeIgniter4 -b v4.0.0-alpha.4 - git clone https://github.com/codeigniter4/CodeIgniter4.git CodeIgniter4 -b v4.0.0-beta.1
- cp -r aauth_temp/* CodeIgniter4 && cd CodeIgniter4 && cp _travis/env .env - cp -r aauth_temp/* CodeIgniter4 && cd CodeIgniter4 && cp _travis/env .env
- composer install --prefer-source - composer install --prefer-source
- composer require spomky-labs/otphp --prefer-source - composer require spomky-labs/otphp --prefer-source

1
app/Config/Aauth.php

@ -151,6 +151,7 @@ class Aauth extends BaseConfig
| 'loginAttemptCookie' | 'loginAttemptCookie'
| |
| Login attempts count & block trough Cookie instead of Login Attempt DB & IP | Login attempts count & block trough Cookie instead of Login Attempt DB & IP
| You can set a string to set the cookie name, default cookie name is logins.
| (default: false) | (default: false)
| |
| 'loginAttemptLimit' | 'loginAttemptLimit'

2
app/Libraries/Aauth.php

@ -227,7 +227,7 @@ class Aauth
{ {
$response = $request->getPostGet('g-recaptcha-response'); $response = $request->getPostGet('g-recaptcha-response');
} }
else if ($this->config->captchaType === 'recaptcha') else if ($this->config->captchaType === 'hcaptcha')
{ {
$response = $request->getPostGet('h-captcha-response'); $response = $request->getPostGet('h-captcha-response');
} }

56
app/Models/Aauth/LoginAttemptModel.php

@ -103,6 +103,18 @@ class LoginAttemptModel
* @return integer * @return integer
*/ */
public function find() public function find()
{
if ($this->config->loginAttemptCookie)
{
helper('cookie');
$cookieName = $this->config->loginAttemptCookie === true ? 'logins' : $this->config->lologinAttemptCookie;
if ($cookie === get_cookie($cookieName))
{
return $cookie;
}
}
else
{ {
$agent = $this->request->getUserAgent(); $agent = $this->request->getUserAgent();
$builder = $this->builder(); $builder = $this->builder();
@ -114,10 +126,9 @@ class LoginAttemptModel
{ {
return $builder->get()->getFirstRow()->count; return $builder->get()->getFirstRow()->count;
} }
else
{
return 0;
} }
return 0;
} }
/** /**
@ -128,6 +139,34 @@ class LoginAttemptModel
* @return boolean * @return boolean
*/ */
public function save() public function save()
{
if ($this->config->loginAttemptCookie)
{
helper('cookie');
$cookieName = $this->config->loginAttemptCookie === true ? 'logins' : $this->config->lologinAttemptCookie;
$expire = strtotime($this->config->loginAttemptLimitTimePeriod) - strtotime('now');
if ($cookie = get_cookie($cookieName))
{
set_cookie($cookieName, $cookie + 1, $expire);
if ($cookie >= $this->config->loginAttemptLimit)
{
return false;
}
else
{
return true;
}
}
else
{
set_cookie($cookieName, 1, $expire);
return true;
}
}
else
{ {
$ipAddress = $this->request->getIPAddress(); $ipAddress = $this->request->getIPAddress();
$agent = $this->request->getUserAgent(); $agent = $this->request->getUserAgent();
@ -166,6 +205,7 @@ class LoginAttemptModel
} }
} }
} }
}
/** /**
* Delete login attempt. * Delete login attempt.
@ -175,14 +215,22 @@ class LoginAttemptModel
* @return boolean * @return boolean
*/ */
public function delete() public function delete()
{
if ($this->config->loginAttemptCookie)
{
helper('cookie');
$cookieName = $this->config->loginAttemptCookie === true ? 'logins' : $this->config->lologinAttemptCookie;
delete_cookie($cookieName);
}
else
{ {
$agent = $this->request->getUserAgent(); $agent = $this->request->getUserAgent();
$builder = $this->builder(); $builder = $this->builder();
$builder->where('user_agent', md5($agent->getBrowser() . ' - ' . $agent->getVersion() . ' - ' . $agent->getPlatform())); $builder->where('user_agent', md5($agent->getBrowser() . ' - ' . $agent->getVersion() . ' - ' . $agent->getPlatform()));
$builder->where('ip_address', $this->request->getIPAddress()); $builder->where('ip_address', $this->request->getIPAddress());
$builder->where('updated_at >=', date('Y-m-d H:i:s', strtotime('-' . $this->config->loginAttemptLimitTimePeriod))); $builder->where('updated_at >=', date('Y-m-d H:i:s', strtotime('-' . $this->config->loginAttemptLimitTimePeriod)));
$builder->delete(); $builder->delete();
}
return true; return true;
} }

Loading…
Cancel
Save