Skip to content
Designing a Scalable Multi-Account Login System: From Phone Auth to Carrier One-Click Login

Designing a Scalable Multi-Account Login System: From Phone Auth to Carrier One-Click Login

This article details the evolution of a unified login system covering phone-based registration, third-party OAuth integration, a normalized database schema separating user profiles from authentication methods, and carrier-based one-click login that reduces authentication time from 20 seconds to 2 seconds.

SpringMeng
SpringMeng
SpringMeng

Introduction

Most modern applications support multiple third-party login providers such as WeChat, QQ, and Weibo, a pattern known as multi-account unified login. The design of data tables and authentication flows is critical for future extensibility. This article outlines the design thinking behind the author's company account module without providing code implementations.

1. Self-Built Login System

1.1 Phone Number Registration and Optimization

1.1.1 Initial Phone Registration Flow

The initial design binds one user per phone number, making the phone number a required field.

Flow:

The user enters a phone number, which is sent to the server. The server checks if the number exists; if not, it generates a random verification code, stores the phone-code pair in Redis with a 5-minute expiry (typical SMS code validity), and sends the code via SMS.

The user submits the received code along with a password and other basic info. The server verifies the code against Redis; on success it creates an account and saves the password.

After registration, the user can log in with phone+password.

Problems identified:

Poor user experience: multiple steps (get code, enter code/password/username) before accessing the app.

Password forgetting forces a reset flow.

1.1.2 Optimized Registration and Login

The optimization weakens the password requirement: both new and existing users can log in directly with phone+verification code, while retaining phone+password as an option.

Flow:

User enters phone number; server generates code, stores in Redis with 5-minute expiry, sends via SMS.

User submits only the code. Server verifies against Redis; on success, logs in the user. Existing users get their profile; new users are prompted to complete optional profile info.

After phone+code login, the user may optionally set a password, enabling future phone+password login.

User table design (simplified): id – user ID user_name – username user_password – password hash user_mobile – phone number state – account status more – other info

1.2 Third-Party Account Integration

1.2.1 Weibo Login

With the advent of Web 2.0, Weibo opened third-party login. The product required adding Weibo login and linking it to the local user table.

Flow:

Client invokes Weibo login UI, user enters credentials, receives access_token on success. The token is used to call Weibo API for user info.

Server creates a local account using the Weibo user info; subsequent logins use the same Weibo account.

Weibo user info table design: id – primary key user_id – local user ID uid – Weibo unique ID access_token – authorization token

1.2.2 The Nightmare of Multiple Providers

Soon QQ, WeChat, NetEase, and others opened login APIs. Each required a new table mirroring the Weibo table and a rewritten login flow, leading to maintenance overhead.

2. Optimized Account System

2.1 Analysis of the Original System

Self-built login: both phone+password and phone+code are forms of user info + credential verification.

Third-party login: also user info + credential, where user info is the third-party ID (unique identifier) and credential is the access_token (a time-limited, rotating password).

2.2 New Account System Design

2.2.1 Data Table Design

The system splits into two tables with a one-to-many relationship:

User Basic Info Table (no passwords, no login identifiers): id – user ID nickname – display name avatar – profile image more – other display-only attributes

User Auth Info Table (all authentication data): id – primary key user_id – foreign key to user basic info identity_type – login type (phone/email) or third-party name (WeChat/Weibo, etc.) identifier – phone number, email, or third-party unique ID credential – password hash for self-built accounts, token for third-party

Key principle: User basic info table and user auth table have a one-to-many relationship.

2.2.2 Login Flows

Phone+verification code

: unchanged from previous optimization. Email/phone+password: user submits identifier and password. Server determines type (e.g., type='phone'), queries auth table with type and identifier, compares submitted password_hash with stored credential. On match, retrieves user info via user_id.

Third-party login (e.g., WeChat): query with type='weixin' and identifier='WeChat openId'. If record exists, login succeeds and token is updated. Assuming secure channel to WeChat server, no further credential verification needed.

2.2.3 Advantages and Disadvantages

Advantages:

Unlimited login type extension; adding a new provider significantly reduces development cost.

Replaces separate phone_verified and email_verified columns with a single verified field in the auth table, giving a unified view of verification status per login method.

Adding timestamp and IP fields to the auth table enables tracking usage habits (e.g., "Weibo not used for 2+ years", "WeChat bound 300 days ago").

Email and phone can remain in the user table purely for display, alongside nickname and avatar, without auth significance.

Supports binding multiple identities of the same type (multiple WeChat accounts, multiple emails, multiple phones) or can be constrained to one per type.

Disadvantages:

When a user has multiple internal login methods (email, username, phone), a password change must update all corresponding auth records; otherwise inconsistent credentials arise (e.g., email+new password and phone+old password both work).

Increased code complexity and logic branching. Example: a user clicks the Weibo authorization link – six distinct scenarios must be handled:

Weibo not registered locally → register, link, and log in.

Weibo already linked, user not logged in → direct login.

Weibo not registered, user logged in with a different Weibo account → resolution depends on whether multiple Weibo bindings are allowed.

Weibo not registered, user logged in → attempt binding.

Weibo already registered, user already logged in with that same Weibo → redundant binding attempt.

Weibo already registered to another user, current user logged in with a different Weibo → conflict resolution required.

3. One-Click Login (Carrier Authentication)

3.1 Background

Reviewing the phone+verification code flow reveals three drawbacks:

Takes 20+ seconds (enter phone, wait SMS, enter code, submit).

Depends on SMS delivery; failures block login.

Security risk: if an attacker knows the phone number and intercepts the code, they can hijack the account.

The core purpose of the code is to prove phone ownership. Since carriers can access SIM card data, they can verify whether the entered number matches the active SIM. Carrier APIs now expose this capability: after the user inputs a phone number, the app calls the carrier to confirm a match, eliminating SMS wait and network dependency. Going further, the carrier can return the current phone number directly, removing the need for the user to type it at all.

3.2 One-Click Login Implementation

One-click login retrieves the active SIM's phone number and uses it directly for authentication, cutting the flow from ~20 seconds to ~2 seconds.

Main steps (using a carrier SDK such as Alibaba Cloud's):

SDK initialization: call the SDK init method with the project's AppKey and AppSecret.

Launch authorization page: invoke the SDK's authorization interface. The SDK requests a phone verification token from the carrier; on success, displays an authorization page showing a masked phone number and carrier terms for user consent.

User consents and logs in: user agrees and taps the login button. The SDK requests a one-time token for this number retrieval and returns it to the client.

Number retrieval: client sends the token to the application server. The server calls the carrier's one-click login API with the token; on success, receives the plain phone number. The server performs login or registration and returns the result to the client.

Alibaba Cloud provides a compatible SDK for China's three major carriers: https://help.aliyun.com/document_detail/121113.html (preserved as technical reference).

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Redisdatabase schemaone-click loginmulti-account loginthird-party OAuthcarrier authenticationSIM verificationunified authentication
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.