0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

9章

Last updated at Posted at 2019-12-18

書いているのは app/models/user.rb
attr_accessor :remember_token #仮想トークン作った

#永続セッションのためにユーザーをデータベースに記憶する
def remember
self.remember_token = User.new_token #ランダムなトークンをリメンバートークンにつっこむ
update_attribute(:remember_digest, User.digest(remember_token)) #DBに保存 今作ったリメンバーをハッシュ化してDBのダイジェストに入れる)
end

--

ランダムなトークンを返す

def User.new_token
SecureRandom.urlsafe_base64
end

渡された文字列のハッシュ値を返す

def User.digest(string)
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
BCrypt::Engine.cost
BCrypt::Password.create(string, cost: cost)
end

--

cookies.permanent[:remember_token] = remember_token #20年のクッキー完成

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?