Skip to content

Commit

Permalink
Refactory auth::too_many_failed_logins() out of
Browse files Browse the repository at this point in the history
auth::validate_too_many_failed_logins() to conceptually separate the
two.
  • Loading branch information
bharat committed Jan 31, 2010
1 parent 1470b99 commit d92ee79
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions modules/gallery/helpers/auth.php
Expand Up @@ -63,20 +63,19 @@ static function logout() {
* After there have been 5 failed login attempts, any failure leads to getting locked out for a
* minute.
*/
static function validate_too_many_failed_logins($name_input) {
$name = is_object($name_input) ? $name_input->value : $name_input;
static function too_many_failed_logins($name) {
$failed_login = ORM::factory("failed_login")
->where("name", "=", $name)
->find();
if ($failed_login->loaded() &&
$failed_login->count > 5 &&
(time() - $failed_login->time < 60)) {
if (is_object($name_input)) {
$name_input->add_error("too_many_failed_logins", 1);
}
return false;
return ($failed_login->loaded() &&
$failed_login->count > 5 &&
(time() - $failed_login->time < 60));
}

static function validate_too_many_failed_logins($name_input) {
if (self::too_many_failed_logins($name_input->value)) {
$name_input->add_error("too_many_failed_logins", 1);
}
return true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/rest/controllers/rest.php
Expand Up @@ -22,7 +22,7 @@ public function index() {
$username = Input::instance()->post("user");
$password = Input::instance()->post("password");

if (empty($username) || !auth::validate_too_many_failed_logins($username)) {
if (empty($username) || auth::too_many_failed_logins($username)) {
throw new Rest_Exception("Forbidden", 403);
}

Expand Down

0 comments on commit d92ee79

Please sign in to comment.