Class: Spree::PasswordLengthValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/validators/spree/password_length_validator.rb

Overview

Default password policy: a length floor with no composition rules, following NIST 800-63B (forced symbols and digits push people toward predictable substitutions). Bounds are configurable via Spree::Config[:minimum_password_length] and [:maximum_password_length].

Replace the whole policy with password_validator=.

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/validators/spree/password_length_validator.rb', line 9

def validate(record)
  password = record.password
  return if password.blank?

  minimum = Spree::Config[:minimum_password_length]
  maximum = Spree::Config[:maximum_password_length]

  if password.length < minimum
    record.errors.add(:password, :too_short, count: minimum)
  elsif password.length > maximum
    record.errors.add(:password, :too_long, count: maximum)
  end
end