我想完全基於cookie和sql db來驗證我的用戶。驗證系統 - 我的安全嗎?
我要做的就是:
1. Once they login, I generate a random string, create a hash from it, save it in the database along with the user id and his IP.
2. I send the hash to the user as cookie
3. Whenever he wants to access something, I verify if his cookie hash matches the one on the server and also if his IP matches. Of yes, he is valid or else, log him out.
4. (As pointed by Akhil) If he clears his browser cookies or anything does not match the information on the database, I clear all the rows with his username and log him out.
Note: I use a session cookie for storing the random hash, which again is generated using the timestamp, and as long as time doesn't repeat itself(I believe), its random in the corect way.
這是好嗎?我怎樣才能讓它變得更好?
我建議不要重新發明輪子。除非你試圖改進現有的方法,否則你可能不會自己實現這一點。 –
如果任何清除cookie或Cookie過期,會發生什麼情況?他將如何能夠登錄?你永遠不能在IP地址上進行中繼。你如何處理動態IP地址?我認爲保持密碼將是一個更簡單的方法 –
「使用時間戳生成」似乎不是隨機的。如果字符串是真正隨機的,那麼散列隨機字符串看起來像是一個額外的,不必要的步驟。 –