Sha256: d148c560acce9ee3eafee1310ad68b93dc4cc96786cc709ae989f0801328f5f4
Contents?: true
Size: 1.81 KB
Versions: 13
Compression:
Stored size: 1.81 KB
Contents
# frozen_string_literal: true require "strong_password" module ThinkFeelDoEngine module Concerns # validates passwords. module ValidatePassword WEAK_PASSWORD_MESSAGE = "is too weak" extend ActiveSupport::Concern included do before_validation :contains_integer, :contains_lowercase_letter, :contains_uppercase_letter, :repeating_characters, on: [:create, :update], if: :password_exists_without_message? validates :password, password_strength: { extra_dictionary_words: :extra_words, use_dictionary: true, min_entropy: ThinkFeelDoEngine:: PasswordValidator::VALID_ENTROPY, message: WEAK_PASSWORD_MESSAGE }, if: :password_exists_without_message? end private def contains_integer set_error_on_password unless password =~ /[0-9]/ end def contains_lowercase_letter set_error_on_password unless password =~ /[a-z]/ end def contains_uppercase_letter set_error_on_password unless password =~ /[A-Z]/ end def email_prefix @email_prefix ||= email[/[^@]+/] end def extra_words [email_prefix, email_prefix.reverse] if email.present? end def password_exists_without_message? password.present? && !errors.full_messages.include?("Password #{WEAK_PASSWORD_MESSAGE}") end def repeating_characters set_error_on_password if password =~ /(.)\1\1/ end def set_error_on_password errors.add(:password, WEAK_PASSWORD_MESSAGE) end end end end
Version data entries
13 entries across 13 versions & 1 rubygems