diff --git a/lib/devise_zxcvbn.rb b/lib/devise_zxcvbn.rb index 426921c..e86761a 100644 --- a/lib/devise_zxcvbn.rb +++ b/lib/devise_zxcvbn.rb @@ -3,8 +3,25 @@ require "zxcvbn" module Devise - mattr_accessor :min_password_score + @@min_password_score = 4 + + def self.min_password_score + @@min_password_score + end + + def self.min_password_score=(score) + if score.is_a?(Integer) && (score >= 0 && score <=4) + if score >= 3 + @@min_password_score = score + else + ::Rails.logger.warn "[devise_zxcvbn] A score of less than 3 is not recommended." + @@min_password_score = score + end + else + raise "The min_password_score must be an integer and between 0..4" + end + end end Devise.add_module :zxcvbnable, :model => "devise_zxcvbn/model"