Login answers two questions: who are you, and can you prove it? You enter something that identifies you, such as a mobile number or email, then prove it is yours with a password or a code sent to your phone. The server checks this and gives you a session, a temporary pass your browser sends with every request so you do not retype your password on every page. Permissions then decide what you may see and do. In Fanann, phone-number sign-in with a one-time code comes ready with your app.
- how does login work in an app
- how do sessions work explained simply
- how to add login to my app
- difference between authentication and authorization
- how are passwords stored securely
- how does OTP login work
What actually happens when you log in?
You open the app, type your mobile number, a four- or six-digit code arrives, you type it, and you are in. It takes seconds, but behind it is a chain of steps whose purpose is for the app to know who you are, make sure you are really you, then remember you as you move between pages.
IllustrationWe will use one example throughout: a small coffee store with three kinds of users: the customer who orders, the staff member who prepares orders, and the owner who sees everything. All three sign in, but each sees something different.
If you are learning how apps work, this article is part of a series that starts with learn programming by building apps and includes the database where your account is saved.
What is the difference between identification, authentication and authorization?
Three words beginners often mix up. Understanding the difference is half of understanding login:
| Step | The question it answers | In the coffee store |
|---|---|---|
| Identification | Who do you say you are? | The customer types their mobile number |
| Authentication | Can you prove it? | They type the code that arrived on that same phone |
| Authorization (permissions) | What are you allowed to see and do? | They see only their own orders, not the owner's dashboard |
Authentication happens once, at sign-in. Permissions are checked on every request. When a staff member presses "View orders", the server asks: is this staff? When they try to open the profit report, it asks: is this the owner? So someone can sign in successfully and still be blocked from a page, which is exactly right.
What are the common ways to log in, and which suits my app?
Each method proves who you are with something different: something you know, like a password; something you have, like your phone; or a trusted account elsewhere:
| Method | How you prove it | Best for |
|---|---|---|
| Email and password | Something you know | Office tools and internal systems |
| Mobile number and one-time code | Something you have: your phone | Stores, bookings and most customer apps in the region |
| Link sent by email | Something you have: your inbox | Apps people open rarely |
| Google sign-in | A trusted account elsewhere | Fast sign-up with one tap, no new password |
| National digital ID | Identity verified by an official body | Services that need official identity checks |
Pick the one that sounds like you to see the advice.
Make mobile number with a one-time code the first option: no password to forget, and you get a working number for contact and delivery. Details in adding phone-number OTP login.
Email and password, or the company's single sign-on if it has one, with clear roles: staff, supervisor, manager. Disable accounts the moment someone leaves.
Consider your country's national digital ID, and check the official body's requirements before you start, because registration has its own conditions.
How does the app remember me after I sign in?
Imagine the app asking for a code on every page. Impossible. So once you have proved who you are, the server gives you a session: a temporary digital pass, like an event wristband, that your browser or app keeps and sends automatically with every request.
- 1You prove who you are
You type your number and the code; the server checks the code is right and has not expired.
- 2You get a session
The server creates a unique, hard-to-guess pass, links it to your account and sends it to your device.
- 3You move freely
With each page your device sends the pass, and the server knows it is you without you typing anything.
- 4The session ends
When you sign out, or after a set time, the pass stops working and you are asked to sign in again.
That is why a shopping app keeps you signed in for weeks while your bank logs you out after minutes. Session length balances comfort and safety: a coffee store can remember you for a month, while a dashboard with financial data should use a shorter one.
How are passwords and codes kept safe?
The golden rule: a well-built app does not know your password. Passwords are never stored as typed. They go through a one-way transformation that produces scrambled text which cannot be reversed. When you sign in, what you typed is transformed the same way and the two results are compared. If the database were stolen, the thief would not find the passwords themselves.
- Short-lived codes: a phone code should expire within a few minutes.
- Attempt limits: after a few wrong tries, acceptance pauses, so nobody can try every number.
- Limits on sending codes again: so nobody uses your app to send thousands of messages at your expense.
- An encrypted connection: everything between the device and the server travels encrypted.
- Generic error messages: "Incorrect code", without revealing whether the number is registered.
What are roles and permissions, and why are they checked on the server?
In the coffee store, customers see products and their own orders, staff see new orders and change their status, and the owner sees everything, including profits and settings. Instead of setting permissions person by person, you give each user a role, and each role a set of permissions. This is called role-based access control.
The key point for beginners: hiding the "Profit report" button from staff on screen is not enough. If a staff member knows the page address and types it in, the server must refuse. Real permissions are checked on the server on every request; the screen only reflects them. It is a perfect example of frontend vs backend.
How do I add login to my app in Fanann?
Building login by hand from scratch is sensitive work: codes, sessions, attempt protection, roles. In Fanann, phone-number sign-in with a one-time code comes ready with the database, and you can ask for email and password or Google sign-in. All you do is describe who signs in and what each role sees.
Add sign-in to my store with a mobile number and a code sent by message, with short-lived codes, attempt and resend limits, and numbers from Qatar, Kuwait, Oman and Egypt only. Three roles: a customer who sees only their own orders; staff who see new orders and change their status but never see profits; and an owner who sees everything and can add or disable staff. Check permissions on the server for every page. In the plan, explain where accounts will be saved and how the session will work.
Try it in FanannAfter building, give the QA Engineer your app's address so it signs in with different roles, tries to open pages that are not theirs, and sends a report with screenshots and the severity of each bug.
How do I understand login through my own app?
The best way to understand login is to trace it in your own app. Open your project's code (the project is yours to read and export) and try these exercises:
- Trace the journey: from the number entry screen, to the request sent to the server, to the place where the code is checked.
- Ask Neo: "Where is the owner permission checked? What happens if a customer tries to open the dashboard?"
- Try it yourself: sign in as a customer in one window and as the owner in another, and compare.
- Request a change: "End the owner dashboard session after one hour", then find the file that changed.
Knowing who you are is one thing; trusting what you ask for is another. A safe app asks both questions every time.
To go deeper into managing staff and their access, read roles and permissions for your team.
Key takeaways
- Login has two steps: saying who you are, then proving it with something you know or something you have.
- After login the app gives you a session, a temporary pass that lets it remember you without your password.
- Passwords are never stored as typed, but in a scrambled form that cannot be reversed.
- Login and permissions are different: the app knowing who you are does not mean it allows you everything.
- Phone-number login with a one-time code suits most apps in our region, with attempt limits and short-lived codes.
Frequently asked questions
How does an app know it is me after I close the page?
Can the app owner see my password?
Which is better: a password or a phone code?
What is the difference between authentication and authorization?
Does login come ready in Fanann?
How do I check that login in my app is secure?
Ask your AI assistant about this
Copy this prompt into the AI assistant you use, then add the details of your own case.
I am reading this guide: “How does login work in an app? A beginner's explanation” https://fanann.com/en/blog/how-app-login-works/ My question: how does login work in an app Use that page as a source and explain the answer step by step for my situation, tell me what to check before I start, and cite the page link.