bcrypt包

作者: yaya_pangdun | 来源:发表于2016-06-02 10:34 被阅读14次

加入

class User < ActiveRecord::Base
  has_secure_password
end

使用

#如果password != password_confirmation,调用save,返回false
user = User.new(name: 'david', password: '123', password_confirmation: '123')

user.save

user.authenticate('123')    #true
user.authenticate('xuji')  #false

User.find_by(name: 'david').try(:authenticate, 'notright')  #false
User.find_by(name: 'david').try(:authenticate, '123')        #true

相关文章

网友评论

      本文标题:bcrypt包

      本文链接:https://www.haomeiwen.com/subject/aunblttx.html