开发者

How do I find user by username rather than email in ruby on rails 3.1?

I've tried a few things but can't seem to get my head round it. I've been practicing and know how to do this using email but how can I do it using username?

def self.authenticate(username, password)
    user = find_by_name(username)
    if user && user.password_hash ==  BCrypt::Engine.hash_secret(password, user.pa开发者_如何学Pythonssword_salt)
    user
    else
      nil
    end
end


Change

user = find_by_name(username)

to

user = find_by_username(username)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜