Skip to contentTalk to us
Building apps

How does login work in an app? A beginner's explanation

How does an app know who you are? A plain guide to login: passwords and phone codes, the session that remembers you, password safety, roles, and adding it to your app.

Fanann Team9 min read
WhatsApp
Quick answer

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.

People look for this as
  • 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.

Illustration: hands holding a phone showing a mobile-number sign-in screen with boxes for the verification code.Illustration
Illustration: hands holding a phone showing a mobile-number sign-in screen with boxes for the verification code.

We 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:

StepThe question it answersIn the coffee store
IdentificationWho do you say you are?The customer types their mobile number
AuthenticationCan 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:

MethodHow you prove itBest for
Email and passwordSomething you knowOffice tools and internal systems
Mobile number and one-time codeSomething you have: your phoneStores, bookings and most customer apps in the region
Link sent by emailSomething you have: your inboxApps people open rarely
Google sign-inA trusted account elsewhereFast sign-up with one tap, no new password
National digital IDIdentity verified by an official bodyServices that need official identity checks
Who will sign in to your app?

Pick the one that sounds like you to see the advice.

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.

  1. 1You prove who you are

    You type your number and the code; the server checks the code is right and has not expired.

  2. 2You get a session

    The server creates a unique, hard-to-guess pass, links it to your account and sends it to your device.

  3. 3You move freely

    With each page your device sends the pass, and the server knows it is you without you typing anything.

  4. 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.

A quick login check for any appTap an item when it is done. Your progress is kept in this browser.

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.

A prompt that adds login and clear roles

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 Fanann
Animated explainer: the QA agent moves through a page in a browser, test cases turn into passes or a bug, then the report appears.
Animated explainerThe QA Engineer testing the app in a browser: trying sign-in, sign-out and protected pages, with checklist items turning green or red.

After 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?
After you prove who you are, the server gives you a session, a temporary digital pass your device keeps and sends with every request. While it is valid the app remembers you; when it expires or you sign out, you sign in again.
Can the app owner see my password?
In a well-built app, no. The password is stored after a one-way transformation that cannot be reversed, and the result is compared at each sign-in without keeping the password itself.
Which is better: a password or a phone code?
For most customer apps in our region, a phone code: no password to forget, and a working contact number. For internal systems a password with clear roles may fit. Either way, attempt limits and short-lived codes matter.
What is the difference between authentication and authorization?
Authentication proves who you are and happens at sign-in. Authorization decides what you may do and is checked on every request. You can sign in successfully and still be blocked from a page your role does not allow.
Does login come ready in Fanann?
Yes. Phone-number sign-in with a one-time code comes ready with the database, and you can ask for other methods such as email or Google sign-in. You describe the roles and what each sees, and review it in the plan before building.
How do I check that login in my app is secure?
Run through the checklist in this article: code expiry, attempt limits, sign-out, and refusing protected pages typed directly. In Fanann the QA Engineer tests these cases and reports with screenshots.

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.

Terms in this article

Your idea deserves to see the light.

Describe it in Arabic or English and Fanann builds, tests and ships it — no coding knowledge needed. Start free, no credit card.