module CommonPassword::Model

The CommonPassword module adds a new validation for Devise Models. No modifications to routes or controllers needed. Simply add :uncommon_password to the list of included modules in your devise module, and all new registrations will be blocked if they use a common password.

Public Instance Methods

password_common?() click to toggle source
# File lib/common_password/model.rb, line 18
def password_common?
  @password_common_index = nil

  password_common_top.present?
end

Private Instance Methods

not_common_password() click to toggle source
# File lib/common_password/model.rb, line 42
def not_common_password
  if password_common?
    errors.add(:password, :"common.top#{password_common_top}")
  end
end
password_common_index() click to toggle source
# File lib/common_password/model.rb, line 30
def password_common_index
  @password_common_index ||= CommonPassword::List.get.index(password.downcase)
end
password_common_top() click to toggle source
# File lib/common_password/model.rb, line 34
def password_common_top
  return nil if password_common_index.nil?

  [100, 1_000, 10_000].each do |index|
    return index if password_common_index < index
  end
end
should_validate?() click to toggle source
# File lib/common_password/model.rb, line 26
def should_validate?
  password.present? && password_required? && self.class.common_active && !self.errors.include?(:password)
end