diff options
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/secure_password.rb | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/activemodel/lib/active_model/secure_password.rb b/activemodel/lib/active_model/secure_password.rb index 6703d5daac..8da08f34ec 100644 --- a/activemodel/lib/active_model/secure_password.rb +++ b/activemodel/lib/active_model/secure_password.rb @@ -1,10 +1,16 @@ require 'active_support/core_ext/object/blank' +require 'active_support/core_ext/class/attribute' require 'bcrypt' module ActiveModel module SecurePassword extend ActiveSupport::Concern + included do + class_attribute :weak_passwords + self.weak_passwords = %w( password qwerty 123456 ) + end + module ClassMethods # Adds methods to set and authenticate against a BCrypt password. # This mechanism requires you to have a password_digest attribute. @@ -44,27 +50,11 @@ module ActiveModel # Specify the weak passwords to be used in the model: # # class User - # weak_passwords %w( password qwerty 123456 mypass ) + # set_weak_passwords %w( password qwerty 123456 mypass ) # end def set_weak_passwords(values) - @weak_passwords = values - end - - # Change the list of weak passwords that will be validated against: - # - # User.weak_passwords = %w( password qwerty 123456 mypass ) - def weak_passwords=(*values) - @weak_passwords = values.flatten + self.weak_passwords = values end - - # Returns the list of current weak passwords defined. Defaults to the standard - # list of 'password', 'qwerty' and '123456' - # - # User.weak_passwords #=> ['password', 'qwerty', '123456'] - def weak_passwords(values = nil) - @weak_passwords ||= %w( password qwerty 123456 ) - end - end # Returns self if the password is correct, otherwise false. |