Permalink
Browse files

Refactory auth::too_many_failed_logins() out of

auth::validate_too_many_failed_logins() to conceptually separate the
two.
  • Loading branch information...
1 parent 1470b99 commit d92ee7954efbf531b40ddd484f76cdfe16c0e53f @bharat bharat committed Jan 31, 2010
Showing with 10 additions and 11 deletions.
  1. +9 −10 modules/gallery/helpers/auth.php
  2. +1 −1 modules/rest/controllers/rest.php
@@ -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;
}
/**
@@ -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);
}

0 comments on commit d92ee79

Please sign in to comment.