Sha256: e2b0fdf5abc38375e543896025d09d02b0f56f6bea006a5da037ad3ae9a477af

Contents?: true

Size: 648 Bytes

Versions: 31

Compression:

Stored size: 648 Bytes

Contents

module ActiveModel
  module Validations
    class PasswordValidator < EachValidator
      REGEXES = {
        :weak   => /(?=.{6,}).*/, # 6 characters
        :medium => /^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$/, #len=7 chars and numbers
        :strong => /^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d\W]).*$/#len=8 chars and numbers and special chars
      }

      def validate_each(record, attribute, value)
        required_strength = options.fetch(:strength, :weak)
        if (REGEXES[required_strength] !~ value)
          record.errors.add(attribute)
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
activevalidators-6.0.0 lib/active_validators/active_model/validations/password_validator.rb
activevalidators-5.1.0 lib/active_validators/active_model/validations/password_validator.rb
activevalidators-5.0.1 lib/active_validators/active_model/validations/password_validator.rb
activevalidators-5.0.0 lib/active_validators/active_model/validations/password_validator.rb
activevalidators-4.1.0 lib/active_validators/active_model/validations/password_validator.rb
activevalidators-4.0.3 lib/active_validators/active_model/validations/password_validator.rb
activevalidators-4.0.2 lib/active_validators/active_model/validations/password_validator.rb
activevalidators-4.0.1 lib/active_validators/active_model/validations/password_validator.rb
activevalidators-4.0.0 lib/active_validators/active_model/validations/password_validator.rb
activevalidators-3.3.0 lib/active_validators/active_model/validations/password_validator.rb
activevalidators-3.2.0 lib/active_validators/active_model/validations/password_validator.rb
activevalidators-3.1.2 lib/active_model/validations/password_validator.rb
activevalidators-3.1.1 lib/active_model/validations/password_validator.rb
activevalidators-3.0.0 lib/active_model/validations/password_validator.rb
activevalidators-2.1.0 lib/active_model/validations/password_validator.rb
activevalidators-2.0.2 lib/active_model/validations/password_validator.rb
activevalidators-2.0.1 lib/active_model/validations/password_validator.rb
activevalidators-2.0.0 lib/active_model/validations/password_validator.rb
activevalidators-1.9.0 lib/active_model/validations/password_validator.rb
activevalidators-1.8.1 lib/active_model/validations/password_validator.rb