Reputation: 15284
I have a web app that requires user authentication, and I want to store the user info on the user machine so the user does not need to re-login.
I thought of using Cookie but I am not sure how safe is that because one can simply use JS console to load and write cookie themselves.
What is a common/popular way of doing that? I am using JS and servlet at the back.
Upvotes: 2
Views: 3817
Reputation: 35760
Nothing that involves saving the actual username/password on the user's computer is "safe"; if you seriously care about safety you just won't do it.
Then again, if you're making a sports score site or something else where security isn't paramount, cookies might just be "secure enough". It just comes down to (as you noted): "what happens if a malicious user gets access to your user's cookies?" Since that's going to be pretty rare (it requires the attacker to have physical access) if the "what happens" isn't too bad, then I'd argue cookies are "safe enough".
Ultimately though, the more popular approach for this sort of thing is just set a fairly long session timeout. The session ID will be stored in the cookies, but not sensitive password info.
Upvotes: 4