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