Module: Devise::Models::Zxcvbnable::ClassMethods

Defined in:
lib/devise_zxcvbn/model.rb

Instance Method Summary collapse

Instance Method Details

#password_score(user, email = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/devise_zxcvbn/model.rb', line 30

def password_score(user, email=nil)
  password = nil
  weak_words = []

  if user.is_a? String
    password = user
  else
    password = user.password
    email = user.email unless email
  end

  weak_words = [email, *DeviseZxcvbn::EmailTokeniser.split(email)] if email

  ::Zxcvbn.test(password, weak_words).score
end