lib/authenticate/model/brute_force.rb in authenticate-0.3.1 vs lib/authenticate/model/brute_force.rb in authenticate-0.3.2
- old
+ new
@@ -1,11 +1,10 @@
require 'authenticate/callbacks/brute_force'
module Authenticate
module Model
-
-
+ #
# Protect from brute force attacks. Lock accounts that have too many failed consecutive logins.
# Todo: email user to allow unlocking via a token.
#
# To enable brute force protection, set the config params shown below. Example:
#
@@ -35,30 +34,29 @@
def self.required_fields(_klass)
[:failed_logins_count, :lock_expires_at]
end
-
def register_failed_login!
self.failed_logins_count ||= 0
self.failed_logins_count += 1
lock! if self.failed_logins_count > max_bad_logins
end
def lock!
- self.update_attribute(:lock_expires_at, Time.now.utc + lockout_period)
+ update_attribute(:lock_expires_at, Time.now.utc + lockout_period)
end
def unlock!
- self.update_attributes({failed_logins_count: 0, lock_expires_at: nil})
+ update_attributes(failed_logins_count: 0, lock_expires_at: nil)
end
def locked?
!unlocked?
end
def unlocked?
- self.lock_expires_at.nil?
+ lock_expires_at.nil?
end
private
def max_bad_logins