mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-24 22:42:27 -05:00
16 lines
556 B
Ruby
16 lines
556 B
Ruby
require_dependency "common_passwords/common_passwords"
|
|
|
|
class PasswordValidator < ActiveModel::EachValidator
|
|
|
|
def validate_each(record, attribute, value)
|
|
return unless record.password_required?
|
|
if value.nil?
|
|
record.errors.add(attribute, :blank)
|
|
elsif value.length < SiteSetting.min_password_length
|
|
record.errors.add(attribute, :too_short, count: SiteSetting.min_password_length)
|
|
elsif SiteSetting.block_common_passwords && CommonPasswords.common_password?(value)
|
|
record.errors.add(attribute, :common)
|
|
end
|
|
end
|
|
|
|
end
|