2013-12-20 16:34:34 -05:00
|
|
|
require_dependency "common_passwords/common_passwords"
|
|
|
|
|
2013-12-19 15:12:03 -05:00
|
|
|
class PasswordValidator < ActiveModel::EachValidator
|
|
|
|
|
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
return unless record.password_required?
|
|
|
|
if value.nil?
|
|
|
|
record.errors.add(attribute, :blank)
|
2013-12-19 16:15:36 -05:00
|
|
|
elsif value.length < SiteSetting.min_password_length
|
|
|
|
record.errors.add(attribute, :too_short, count: SiteSetting.min_password_length)
|
2013-12-20 16:34:34 -05:00
|
|
|
elsif SiteSetting.block_common_passwords && CommonPasswords.common_password?(value)
|
|
|
|
record.errors.add(attribute, :common)
|
2013-12-19 15:12:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|