I'm trying to understand how does authentication happens on website. I'm not asking for code, I'm trying to understand the concept. When user comes to website for the first time, he/she logins and my server authenticate it. But when user moves to next page, as http
is stateless, how does server know that current user is the same user who has logged in?
I've thought of couple of ways, which are as follows, but I'm not convinced that they will work flawlessly. To addon, they might not be efficient as well.
- Send
userid/password
in every request - very bad design, as userid/password can be hacked! - Use
cookies
- again it has a flaw, that user can send the cookie to his/her friend then my server would be in ambiguous state :|
Is there a better way to authenticate users on subsequent request?
Note: I'm not allowed use https
protocol as it is slower than http
and there are some business reasons.