Sha256: b2e13931fb5214173e41240eb55535e4a45187c084969fa3df29aed854216dde
Contents?: true
Size: 1.01 KB
Versions: 6
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true # Password complexity validator # Options: # - digit: minimum number of digits in the validated string # - lower: minimum number of lower-case letters in the validated string # - symbol: minimum number of punctuation characters or symbols in the validated string # - upper: minimum number of upper-case letters in the validated string class DeviseSecurity::PasswordComplexityValidator < ActiveModel::EachValidator PATTERNS = { digit: /\p{Digit}/, digits: /\p{Digit}/, lower: /\p{Lower}/, upper: /\p{Upper}/, symbol: /\p{Punct}|\p{S}/, symbols: /\p{Punct}|\p{S}/ }.freeze def validate_each(record, attribute, value) active_pattern_keys.each do |key| minimum = [0, options[key].to_i].max pattern = Regexp.new PATTERNS[key] unless (value || '').scan(pattern).size >= minimum record.errors.add attribute, :"password_complexity.#{key}", count: minimum end end end def active_pattern_keys options.keys & PATTERNS.keys end end
Version data entries
6 entries across 6 versions & 1 rubygems