Permalink
Browse files

Use class_attribute to ensure weak_passwords are inheritable.

  • Loading branch information...
josevalim committed Dec 19, 2010
1 parent 6c217f9 commit 6d80f3a1ba52248cb8837af5ad40a23dc4fea213
Showing with 8 additions and 18 deletions.
  1. +8 −18 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 @@ def has_secure_password
# 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.

0 comments on commit 6d80f3a

Please sign in to comment.