久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

我應(yīng)該在 cookie 中存儲什么來實現(xiàn)“記住我"

What should I store in cookies to implement quot;Remember mequot; during user login(我應(yīng)該在 cookie 中存儲什么來實現(xiàn)“記住我?在用戶登錄期間)
本文介紹了我應(yīng)該在 cookie 中存儲什么來實現(xiàn)“記住我"?在用戶登錄期間的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我的網(wǎng)站有一個登錄系統(tǒng),存儲在數(shù)據(jù)庫中的用戶詳細信息是用戶 ID(每個用戶和標(biāo)識符唯一的)、電子郵件地址強>(唯一)、顯示名稱(非唯一)、密碼會員身份.
現(xiàn)在我應(yīng)該在 cookie 中存儲什么?我正在考慮僅將用戶 ID 存儲在具有到期日期的 cookie 中,然后如果用戶在注冊后重新訪問我的網(wǎng)站,請檢查 cookie 并讓他登錄(這對我來說不合適)并銷毀 cookie如果他決定退出.
*稍微解釋一下也會很有幫助.謝謝

I have a login system in place for my website, the details of the user which are stored in the database are userid(unique for every user and identifier), email address(unique), display name(not unique), password and membersince.
Now what should I store in the cookies? I was thinking about storing just the userid in the cookie with an expiration date and then if the user revisits my website after signing up check for the cookie and log him in( which kind of doesn't look right to me) and destroy the cookie if he decides to log out.
*A little explanation would also be very helpful. Thanks

推薦答案

如果您使用只有您的應(yīng)用程序知道的密鑰對其進行簽名,則您只能將用戶 ID 存儲在 cookie 中.否則,用戶可能會將 cookie 更改為任何內(nèi)容并以其他人的身份登錄.因此,如果您想存儲用戶 ID,還需要使用密鑰存儲用戶 ID 的哈希值(理想情況下使用 HMAC) 并且當(dāng)您想登錄它們時,計算相同的哈希值并將其與來自 cookie 的哈希值進行比較.另一種解決方案是生成一個隨機令牌,將其存儲在數(shù)據(jù)庫中并在 cookie 中使用它.如果它足夠長且足夠隨機,那么有人猜測另一個人的令牌的可能性很小.

You can only ever store the userid in a cookie if you sign it with a secret key that only your applications knows. Otherwise it's possible for the user to change the cookie to anything and login as somebody else. So, if you want to store the userid, store also a hash of the user id with the secret key (ideally using HMAC) and when you want to log them in, calculate the same hash and compare it to the hash from the cookie. Another solution is to generate a random token, store it in the database and use that in the cookie. If it's long and random enough, there is very little chance somebody would guess another person's token.

這篇關(guān)于我應(yīng)該在 cookie 中存儲什么來實現(xiàn)“記住我"?在用戶登錄期間的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 丁香色婷婷| 99国内精品久久久久久久 | 欧美在线激情 | 久久精品国产一区二区三区不卡 | 色av一区二区三区 | 伊人91在线 | 午夜影院在线免费观看视频 | 精品久久视频 | 国产精品美女久久久久aⅴ国产馆 | 日日夜夜影院 | 日韩免费中文字幕 | 亚洲国产欧美在线 | 日韩五月天 | 国产偷录视频叫床高潮对白 | 欧美福利 | 精品视频99 | 亚洲自拍偷拍欧美 | 日本精品久久久一区二区三区 | 久久99视频 | 欧美成人一区二区三区 | 欧美精品一区二区在线观看 | 91亚洲国产成人久久精品网站 | 精品国产一区二区三区久久久久久 | 在线成人一区 | 国产精品久久久久久久久久久久午夜片 | 欧美日韩国产综合在线 | 一道本不卡视频 | 国产一区欧美 | 欧美日韩1区2区 | 国产亚洲精品久久午夜玫瑰园 | 天天躁日日躁狠狠躁2018小说 | 亚洲永久免费观看 | 男女爱爱网站 | 久久国产精品免费一区二区三区 | 国产精久久久 | 一区二区三区国产 | 久久精品国产一区二区三区 | 国产精品视频一区二区三区四区国 | 国产乱码久久久 | 国产婷婷精品 | 97av在线 |