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

我應該在 cookie 中存儲什么來實現“記住我"

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

問題描述

我的網站有一個登錄系統,存儲在數據庫中的用戶詳細信息是用戶 ID(每個用戶和標識符唯一的)、電子郵件地址強>(唯一)、顯示名稱(非唯一)、密碼會員身份.
現在我應該在 cookie 中存儲什么?我正在考慮僅將用戶 ID 存儲在具有到期日期的 cookie 中,然后如果用戶在注冊后重新訪問我的網站,請檢查 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

推薦答案

如果您使用只有您的應用程序知道的密鑰對其進行簽名,則您只能將用戶 ID 存儲在 cookie 中.否則,用戶可能會將 cookie 更改為任何內容并以其他人的身份登錄.因此,如果您想存儲用戶 ID,還需要使用密鑰存儲用戶 ID 的哈希值(理想情況下使用 HMAC) 并且當您想登錄它們時,計算相同的哈希值并將其與來自 cookie 的哈希值進行比較.另一種解決方案是生成一個隨機令牌,將其存儲在數據庫中并在 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.

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

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

相關文檔推薦

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 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
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 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 亚洲午夜av | 九九国产 | 国产区一区| 国产精品99免费视频 | 成人av一区二区三区 | 欧美极品在线观看 | av官网在线 | 91黄在线观看 | 日韩中文视频 | 网站黄色在线免费观看 | 91精品国产麻豆 | 亚洲黄色av | 欧美激情亚洲天堂 | 综合网视频 | 国产一区久久久 | 久草www| 夜夜夜夜夜夜曰天天天 | 欧美精品被| 青娱乐国产 | 欧美日韩国产精品一区 | 欧洲成人免费视频 | 国产精品久久久久久久久久尿 | 免费黄色的网站 | 久久99精品久久久久久狂牛 | 亚洲 中文 欧美 日韩 在线观看 | 亚洲综合精品 | 成人在线视频一区 | 欧美亚洲综合久久 | 一级免费看片 | 国产激情在线观看 | 亚洲精品久久久久中文字幕欢迎你 | 91麻豆精品国产91久久久更新资源速度超快 | 日日干日日操 | 国产aⅴ精品 | 久久精品中文 | 中文字幕亚洲区一区二 | 老外黄色一级片 | 中文字幕一区二区三区在线乱码 | 亚洲成人高清 | 欧洲免费视频 | 成人精品久久 |