aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/secure_password.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-12-19 13:30:19 +0100
committerJosé Valim <jose.valim@gmail.com>2010-12-19 13:31:48 +0100
commit6d80f3a1ba52248cb8837af5ad40a23dc4fea213 (patch)
tree56cea7d39611c283101bf3fdbedb0ba19a3c3d67 /activemodel/lib/active_model/secure_password.rb
parent6c217f98db6984c8d000103ac3cf66970eeaeb3f (diff)
downloadrails-6d80f3a1ba52248cb8837af5ad40a23dc4fea213.tar.gz
rails-6d80f3a1ba52248cb8837af5ad40a23dc4fea213.tar.bz2
rails-6d80f3a1ba52248cb8837af5ad40a23dc4fea213.zip
Use class_attribute to ensure weak_passwords are inheritable.
Diffstat (limited to 'activemodel/lib/active_model/secure_password.rb')
-rw-r--r--activemodel/lib/active_model/secure_password.rb26
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.