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

用 PHP 設計一個安全的自動登錄 cookie 系統

Designing a secure auto login cookie system in PHP(用 PHP 設計一個安全的自動登錄 cookie 系統)
本文介紹了用 PHP 設計一個安全的自動登錄 cookie 系統的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想為用戶檢查自動登錄選項.基本上,這意味著 cookie 將存儲在客戶端.

I want to have an auto login option check for a user. Basically that means a cookie will be stored on the client side.

現在的問題是,如何確保 cookie 不會被欺騙/修改.

Now the question is, how do I make it secure so the cookie will can not be spoofed/modified.

我的一個朋友建議使用一個 db 表來存儲 session_id、用戶的 ip、瀏覽器信息等,然后在用戶再次訪問該網站時比較所有這些信息.

One of my friends suggest having a db table that stores the session_id, user's ip, browser info, etc and then compare it all that information once a user goes to the website again.

我覺得有一個單獨的桌子有點太麻煩了.還有另一種方法嗎?也許帶有令牌或類似的東西?

I feel like having a separate table for that is a bit too much trouble. Is there another way to do it? Maybe with tokens or something like that?

推薦答案

你想要這個臭名昭著的 cookie 越安全,它就越麻煩.如果您的用戶應該特別安全,您將不得不采用最麻煩的方法.

The more secure you want this infamous cookie, the more trouble it's going to be for you. If your users should be particularly secure, you will have to go with the most troublesome approach.

如果您想盡可能安全,您應該只接受帶有 https 的 cookie.如果 cookie 通過 http 被接受,它可以被嗅探和竊取.

You should only accept this cookie with https if you want to be as secure as possible. If the cookie is accepted over http, it can be sniffed and stolen.

我建議 cookie 根本沒有用戶數據(如您所建議的令牌).不幸的是,這將需要另一個表.當用戶登錄并選擇保持登錄"時,在此表中創建一個條目.該條目可以是任何無意義的值(例如 md5(uniqid('', true));.此令牌在數據庫中可以是唯一的并映射到用戶 ID.

I would recommend that the cookie have no user data at all (a token, as you suggested). This will, unfortunately, require another table. When a user logs in and chooses "keep login," create an entry in this table. The entry can be any meaningless value (such as md5(uniqid('', true));. This token can be unique in the DB and mapped to a user's ID.

當用戶訪問您的網站時,您可以檢查該 cookie 的值并獲取它所屬的用戶并登錄.此時,您銷毀舊令牌并創建一個新令牌.破壞"可以意味著很多事情.您可以將其從數據庫中完全刪除,也可以設置一個禁用令牌的標志.您可能希望允許多次使用相同的令牌,以防收到 cookie 但由于某種原因無法通過身份驗證,但我認為這是不安全的.您可能還想存儲令牌的時間戳,并且只有在某個有限的時間段內(例如 30 天)才接受它.

When a user visits your website, you can check the value of that cookie and get the user it belongs to and log them in. At this point, you destroy the old token and create a new one. "Destroy" can mean many things. You can delete it from the DB entirely or have a flag that disables the token. You may want to allow the same token to be used multiple times in case the cookie is received but the authentication doesn't go through for some reason, but I think this is insecure. You may also want to store the timestamp of the token and only accept it if it's been some limited period of time (30 days for example).

正如您的朋友所指出的,您可以存儲其他信息,例如用戶代理、IP 地址等,但即使使用相同的瀏覽器(尤其是移動瀏覽器)并且如果不接受用戶的持續登錄,這些信息也可能會發生變化因此,這可能會給他們帶來不和諧和不便.

As your friend points out, you can store other information such as user agent, IP address, etc., but these may change even with the same browser being used (especially with mobile) and if a user's persistent login is not accepted because of this, it could be jarring and inconvenient to them.

如果你真的不想創建另一個表,那么你將不得不通過存儲某種方式從 cookie 值中獲取用戶的 ID.這不太安全.

If you really don't want to create another table, then you will have to store some way to acquire the user's ID from the cookie value. This is less secure.

這篇關于用 PHP 設計一個安全的自動登錄 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| 日韩色图视频 | 国产精品久久777777 | 午夜欧美a级理论片915影院 | 日韩精品极品视频在线观看免费 | 欧美日韩国产综合在线 | 天天综合91 | 国产美女精品 | 国产精品久久久亚洲 | 国产一区久久精品 | 国产亚洲一区二区三区在线观看 | 黄色大片视频 | 日本一区高清 | 91精品国产综合久久久久久 | 免费精品视频在线观看 | 亚洲欧美一区二区三区视频 | 草草视频在线观看 | 国产一区二区在线免费观看 | av性色全交蜜桃成熟时 | 91极品欧美视频 | 久久机热| 国产区第一页 | 操操日| 亚洲精品久久久久中文字幕欢迎你 | 欧美综合自拍 | 男人的天堂久久 | 精品区| 成人免费在线观看 | 久久精品亚洲国产奇米99 | 久久国产欧美一区二区三区精品 | 一区在线观看 | 国产精品久久二区 | 99热碰| 99精品国产一区二区青青牛奶 | 欧美激情国产精品 |