Sha256: 57d5c143f824ade38cc4397a8fbef5dee9d516e9fbf64a969bdbbbd4ae1acb31

Contents?: true

Size: 663 Bytes

Versions: 2

Compression:

Stored size: 663 Bytes

Contents

module Devise
  module Models
    module Zxcvbnable
      extend ActiveSupport::Concern

      delegate :min_password_score, to: "self.class"

      included do
        validate :not_weak_password, if: :password_required?
      end

      private

      def not_weak_password
        password_score = ::Zxcvbn.test(password, [self.email]).score
        if password_score < min_password_score
          self.errors.add :password, :weak_password, score: password_score, min_password_score: min_password_score
          return false
        end
      end

      module ClassMethods
        Devise::Models.config(self, :min_password_score)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
devise_zxcvbn-1.0.0 lib/devise_zxcvbn/model.rb
devise_zxcvbn-0.0.1 lib/devise_zxcvbn/model.rb