Sha256: 73949b9c209422f21fff6bbe69c3c7369d2aeed607c5c8e654e69b3d40ca353c

Contents?: true

Size: 521 Bytes

Versions: 2

Compression:

Stored size: 521 Bytes

Contents

class PasswordValidator < ActiveModel::EachValidator

  def validate_each(record, attribute, value)
    strict_mode = options[:strict] || false

    if strict_mode
      format = /^(?=^.{6,18}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$/ # Strict: requires length between 6 and 18, one number, lowercase, upcase letter
    else
      format = /^[a-z0-9!@#$%^&*_-]{6,18}$/
    end

    unless value =~ format
      record.errors[attribute] << (options[:message] || I18n.t('errors.messages.password'))
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flash_validators-1.1.0 lib/flash_validators/validators/password_validator.rb
flash_validators-1.0.0 lib/flash_validators/validators/password_validator.rb