提交 43433b3f 编写于 作者: D David Heinemeier Hansson

Instance methods shouldnt be added until you actually call has_secure_password

上级 fd1cf13f
......@@ -37,22 +37,26 @@ def has_secure_password
validates_confirmation_of :password
validates_presence_of :password_digest
include InstanceMethodsOnActivation
end
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
module InstanceMethodsOnActivation
# 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
end
# Encrypts the password into the password_digest attribute.
def password=(unencrypted_password)
@password = unencrypted_password
self.password_digest = BCrypt::Password.create(unencrypted_password)
# Encrypts the password into the password_digest attribute.
def password=(unencrypted_password)
@password = unencrypted_password
self.password_digest = BCrypt::Password.create(unencrypted_password)
end
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册