Sha256: a1a6478b2634d9727bac4e65e256d5e6a442a12af7d5e0262057547e39b9735f
Contents?: true
Size: 1.01 KB
Versions: 62
Compression:
Stored size: 1.01 KB
Contents
# TODO: Extract out into separate gem for v3 class PasswordValidator < ActiveModel::EachValidator MIN_LENGTHS = { weak: 7, medium: 7, strong: 8 } REGEXES = { weak: %r[(?=.{#{MIN_LENGTHS[:weak]},}).*], # 7 characters medium: %r[^(?=.{#{MIN_LENGTHS[:medium]},})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$], # len=7 chars and numbers strong: %r[^.*(?=.{#{MIN_LENGTHS[:strong]},})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d\W]).*$] # len=8 chars and numbers and special chars } def validate_each(record, attribute, value) return if value.blank? required_strength = options.fetch(:strength, :weak) if !required_strength.in?(REGEXES.keys) && record.respond_to?(required_strength) required_strength = record.send(required_strength) end if REGEXES[required_strength] !~ value record.errors.add( attribute, "password_#{required_strength}_requirements".to_sym, min: MIN_LENGTHS[required_strength] ) end end end
Version data entries
62 entries across 62 versions & 1 rubygems
Version | Path |
---|---|
workarea-core-3.4.13 | lib/workarea/validators/password_validator.rb |
workarea-core-3.4.12 | lib/workarea/validators/password_validator.rb |