How it works
Logging in is called authenticationAuthenticationChecking who a user is, usually with a password, a code or biometrics.Open in glossary →: proving who you are. It’s different from authorizationAuthorizationChecking what a logged-in user is allowed to see or do.Open in glossary →, which decides what you’re allowed to do once you’re in (for example, only admins can issue refunds).
Here’s what happens behind the screen when you tap Log in:
1Sends email + password over HTTPS
POST /login2Finds the user and compares password hashes
3Match found
4Creates a session and returns a token
token: 8f2a…5Stores the token safely (Keychain, Keystore or a cookie)
6Every next request carries the token
GET /orders7Checks the token and answers
200 · Anna's orders
- You enter your credentials. Usually an email (or username or phone number) and a password.
- The app sends them to the server. Always over an encrypted HTTPSHTTPSThe secure version of HTTP; traffic between the browser or app and the server is encrypted.Open in glossary → connection, and inside the request body (the part of the message that isn’t shown in the address), never in the URL (the web address).
- The server checks them. It looks up the account and compares the password with a stored hashPassword hashingStoring a one-way scrambled version of a password instead of the password itself.Open in glossary → (a scrambled version that can’t be turned back into the password). A good server never stores your actual password.
- The server starts a sessionSessionThe period during which a user stays logged in without entering their credentials again.Open in glossary →. It sends back a tokenSession tokenA string the server issues after login that proves who you are on later requests.Open in glossary →: a long random string that works like a wristband at a festival. You showed your ticket once, and now the wristband gets you in.
- The app stores the token. Mobile apps use secure storage (iOS KeychainKeychainiOS secure storage for small secrets like tokens and passwords; items can survive uninstalling the app.Open in glossary →, Android KeystoreAndroid KeystoreAndroid's system for storing cryptographic keys so apps can use them but not extract them.Open in glossary →). Websites usually use a cookieCookieA small piece of data a website stores in your browser, for example to keep you logged in.Open in glossary →.
- Every next request carries the token. “Show my orders” works because the server sees the token and knows it’s you.
- Logging out (or expiry) ends the session. The server invalidates the token, so even a copied token stops working.
The family of login features
“Login” is rarely just one screen. Here’s what you’ll meet in real projects:
| Feature | What it does | What to watch out for |
|---|---|---|
| Sign up (registration) | Creates a new account: name, email, password, maybe terms checkbox | Password rules really enforced, duplicate emails, confirmation email |
| Log in (sign in) | Proves you own an existing account | Wrong-credential handling, lockout, “remember me”, sessions |
| Password reset | “Forgot password?” sends a one-time link or code by email or SMS | Link expires, works only once, old password stops working, generic message |
| Two-factor authentication (2FA) | After the password, asks for a second proof: SMS code, authenticator app code, or a push approval | Wrong or expired codes, resend limits, “trust this device” |
| Social loginSocial loginSigning in through another provider, like Sign in with Apple or Continue with Google.Open in glossary → | “Sign in with Apple” or “Sign in with Google” lets another company vouch for you | Canceling halfway, Apple’s “Hide My Email” (the app gets a made-up forwarding address instead of the real one), linking to an existing account |
| Biometrics | Face ID, Touch ID or fingerprint unlocks a saved login on the device | Fallback to password, new fingerprint added, biometrics turned off |
| Logout | Ends the session on this device (sometimes “log out everywhere”) | Back button, cached screens, other tabs and devices |
Example requirements
Before you test, you need to know what “correct” means. Here’s a realistic user storyUser storyA short description of a feature from the user's point of view.Open in glossary → for a grocery delivery app, with acceptance criteriaAcceptance criteriaConditions a user story must meet to be considered done and accepted.Open in glossary →:
Notice how many criteria are about things other than “it logs in”. Criteria 2, 4, 5, 7, 9 and 10 each prevent a real bug that teams ship all the time.
Why “generic error message” matters
If the app says “No account with this email” for one address and “Wrong password” for another, an attacker can feed it a list of emails and learn which people have accounts. That’s called account enumerationAccount enumerationFinding out which emails are registered from differences in error messages or responses.Open in glossary →. They can then target those people with phishing (fake emails or pages that trick people into giving away their password) or password guessing.
Reveals which emails exist
No account found with this email.
An attacker now knows maria@example.com is not a customer, and will happily try the next address.
Same message for both cases
Email or password is incorrect.
The attacker learns nothing. A real customer still knows what to do: check both and try again.
Check this part
After the server checks your password, what does it send back so the app knows it's you on the next requests?
Which error message is the safest for a failed login?