Skip to content

Instantly share code, notes, and snippets.

@taisyo7333
Last active November 30, 2016 10:24
Show Gist options
  • Save taisyo7333/1a4a62588be6afd5787d78ce0cc0bd6d to your computer and use it in GitHub Desktop.
Save taisyo7333/1a4a62588be6afd5787d78ce0cc0bd6d to your computer and use it in GitHub Desktop.
Rails Tutorial Memo

http://railstutorial.jp/chapters/log_in_log_out?version=4.2#cha-log_in_log_out

上で説明した設計やセキュリティ上の考慮事項を元に、以下の方針で永続的セッションを作成することにします。

  1. 記憶トークンにはランダムな文字列を生成して用いる。
  2. ブラウザのcookiesにトークンを保存するときには、有効期限を設定する。
  3. トークンはハッシュ値に変換してからデータベースに保存する。
  4. ブラウザのcookiesに保存するユーザーIDは暗号化しておく。
  5. 永続ユーザーIDを含むcookiesを受け取ったら、そのIDでデータベースを検索し、記憶トークンのcookiesがデータベース内のハッシュ値と一致することを確認する。

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment