Web Authentication and Session Security
Explain how cookies and session IDs keep a user logged in, and choose session settings that stop sessions being stolen or reused.
How the app remembers that you logged in
Mrs. Gokhale logs in to the Tulsi Health app once, with her phone number and a code sent by SMS. After that she can open her order history, add medicines to her cart and pay, moving through a dozen screens without logging in again. That is surprising when you know that every request from her phone arrives at the server as a separate message, and the server has no built-in memory of the message before it. Something must tell the server, on the twelfth request, that this is still Mrs. Gokhale. That something is a session, and protecting it matters as much as protecting the password.
Logging in: proving who you are
Proving that you are who you claim to be is called authentication, and a login screen is where it happens. There are three kinds of proof. Something you know is a password or PIN. Something you have is your phone, which receives a one-time password (OTP), a short code that works once and expires within minutes. Something you are is a fingerprint or face. Tulsi Health customers log in with their phone number and an OTP, while staff using the pharmacy portal give a username, a password and an OTP: two kinds of proof, called two-step login.
A well-built login page also refuses to help guessers. It gives the same message, "Phone number or password incorrect", whether the account exists or not, so a stranger cannot use it to learn who is a customer. It slows down repeated failures, for example by pausing the account for a few minutes after five wrong attempts. And it runs only over HTTPS, the protected form of web traffic, so the password and OTP cannot be read on the way.
Cookies: a small note the browser carries
Once you have proved who you are, the server gives your browser a small note to carry. A cookie is a small piece of text that a website asks your browser to store and then send back automatically with every later request to that same website. Websites use cookies for many harmless things, such as remembering that you chose Marathi as your language or what is in your cart. The most important cookie, though, is the one that says "this browser belongs to someone who has logged in".
Cookies are sent without you doing anything, which is what makes them convenient and also what makes them valuable. Whoever holds the login cookie is treated as the person who logged in. A server cannot see a face; it sees only the note.
Sessions and session identifiers
A session is the stretch of time during which the server remembers a logged-in user, from login until logout or until it expires. The server keeps a list of current sessions: each entry has a session identifier (session ID), a long random string such as k7Qx9…, plus who it belongs to and when it was last used. The session ID itself goes to the browser inside a cookie. On every request the browser sends the cookie back, the server finds that ID in its list, and it knows who is asking.
A railway station cloakroom works the same way. You hand over your bag and receive a token numbered 4721. When you come back, the clerk hands the bag to whoever presents token 4721, without looking at faces or asking for identity papers. The token is convenient for you and the clerk, but if you drop it on the platform, the person who picks it up gets your bag.
A session ID works like a cloakroom token. After login, the server trusts the token, so whoever holds it is treated as its owner.
The password and OTP are used once. From step 4 onwards, the session ID alone proves who is asking.
Step through a login on the staff portal below. The second version shows what happens when logout only clears the screen and a copy of the session cookie is in the wrong hands.
How sessions are stolen, and what stops it
Taking over someone's session by getting hold of their session ID is called session hijacking. It does not need the password at all, which is why it is attractive to attackers. Session IDs leak in a few common ways: an ID that is short or follows a pattern (1001, 1002, 1003) can simply be guessed; a cookie sent without HTTPS can be read by someone on the same public Wi-Fi; a browser left logged in on a shared counter laptop hands the session to the next person; and a session that never expires turns any of these into a problem that lasts for weeks.
Good session management closes each of those gaps. Session IDs should be long and random, so that guessing is hopeless. The cookie should carry two settings: Secure, which means the browser sends it only over HTTPS, and HttpOnly, which means scripts running inside the web page cannot read it, so a malicious script slipped into a page cannot copy it. Sessions should end after a period of inactivity, called an idle timeout, and after a maximum total time even if they are being used. Logout must delete the session from the server's list, not just clear the screen. And the server should issue a fresh session ID at every login, so that an ID someone planted or saw before login is worthless afterwards.
Each weak habit on the left leaves one way to steal or reuse a session. The matching habit on the right closes it.
Timeouts involve a trade-off that you can feel at a busy pharmacy counter. Too long, and a login left open during a tea break is usable by anyone who walks up. Too short, and Farida is logged out in the middle of reading a prescription, so staff start sharing one login or keep tapping the screen to stay awake, which is worse. A banking app may choose five minutes; a pharmacy counter might settle somewhere between ten and thirty.
You are Neha, setting the session rules for the staff portal used on all 14 counter laptops. Adjust the settings below until every check in the mission is met, and read what each setting changes.