Skip to content

Commit

Permalink
Add missing require and remove extra module.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Dec 19, 2010
1 parent d592fa9 commit b8f6dd8
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions activemodel/lib/active_model/secure_password.rb
@@ -1,3 +1,4 @@
require 'active_support/core_ext/object/blank'
require 'bcrypt'

module ActiveModel
Expand Down Expand Up @@ -43,30 +44,28 @@ def has_secure_password
end
end

module InstanceMethods
# Returns self if the password is correct, otherwise false.
def authenticate(unencrypted_password)
if BCrypt::Password.new(password_digest) == unencrypted_password
self
else
false
end
# Returns self if the password is correct, otherwise false.
def authenticate(unencrypted_password)
if BCrypt::Password.new(password_digest) == unencrypted_password
self
else
false
end
end

# Encrypts the password into the password_digest attribute.
def password=(unencrypted_password)
@password = unencrypted_password
self.password_digest = BCrypt::Password.create(unencrypted_password)
end
# Encrypts the password into the password_digest attribute.
def password=(unencrypted_password)
@password = unencrypted_password
self.password_digest = BCrypt::Password.create(unencrypted_password)
end

private

private
def password_must_be_strong
if password.present?
errors.add(:password, "must be longer than 6 characters") unless password.size > 6
errors.add(:password, "is too weak and common") if WEAK_PASSWORDS.include?(password)
end
end
def password_must_be_strong
if password.present?
errors.add(:password, "must be longer than 6 characters") unless password.size > 6
errors.add(:password, "is too weak and common") if WEAK_PASSWORDS.include?(password)
end
end
end
end

0 comments on commit b8f6dd8

Please sign in to comment.