Sha256: bb53e019b7b59f9798c8893913a9a441add0ebef126141506a338a89fb4fe707

Contents?: true

Size: 547 Bytes

Versions: 10

Compression:

Stored size: 547 Bytes

Contents

class PasswordValidator < ActiveModel::EachValidator

  def validate_each(record, attribute, value)
    unless valid?(value, options)
      record.errors[attribute] << (options[:message] || I18n.t('flash_validators.errors.messages.password'))
    end
  end

  private

  def valid_format?(value, options)
    if options[:strict]
      value =~ /^(?=^.{6,18}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$/
    else
      value =~ /^[a-z0-9!@#$%^&*_-]{6,18}$/
    end
  end

  def valid?(value, options)
    valid_format?(value, options)
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
flash_validators-3.0.11 lib/flash_validators/validators/password_validator.rb
flash_validators-3.0.10 lib/flash_validators/validators/password_validator.rb
flash_validators-3.0.9 lib/flash_validators/validators/password_validator.rb
flash_validators-3.0.8 lib/flash_validators/validators/password_validator.rb
flash_validators-3.0.7 lib/flash_validators/validators/password_validator.rb
flash_validators-3.0.6 lib/flash_validators/validators/password_validator.rb
flash_validators-3.0.5 lib/flash_validators/validators/password_validator.rb
flash_validators-3.0.4 lib/flash_validators/validators/password_validator.rb
flash_validators-3.0.3 lib/flash_validators/validators/password_validator.rb
flash_validators-3.0.2 lib/flash_validators/validators/password_validator.rb