当前位置:网站首页>[featured] how do you design unified login with multiple accounts?
[featured] how do you design unified login with multiple accounts?
2022-06-24 21:50:00 【Student Li】
Unified login of multiple accounts
Explanation of the name
The multi account here is different from the system level , When we talk about multi account system, we mean , In our Internet applications , Our app will use multiple third-party accounts to log in , For example, the common APP: NetEase 、 WeChat 、QQ wait .
Content
Through this article :
Can learn : The details of technical solutions for multiple users , And the corresponding table design , Process design .
You can't learn : Like any other article , I won't have specific code implementation details here , The plan is right , How to write the code

Architecture evolution
Initial stage of entrepreneurship
It comes down to the fact that the number of users is relatively small at this time , I haven't even connected to the account system of other third parties mentioned above , Just a self built system can satisfy , If we build our own system , At present, there are
User name password registration login
This method will be used in many initial website construction , To register first , Log in again , In the older cms This shadow can be found in .
flow chart :

Process description :
The front end will be user name 、 Password sent to server , The server makes regular judgments , Judge user name 、 Whether the password length meets , Whether the user name is repeated or not , The condition does not directly return the corresponding error code to the front end , Here is the password field , In order to prevent the transmission process is truncated , It is recommended to encrypt and upload again , By default, our transmission password will have one md5 encryption , Then record to the database for another layer of encryption , Even if it's out of storage, it's ok , Don't store passwords in plain text .
After the verification is passed , Just write the username and password to the database , And carry out the operation of the back points distribution, etc , Not here .
Now log in , The front end will be user name , The password is sent to the server , The server will first verify whether the number of logins exceeds the set threshold , If you exceed, you can only wait for the house to be closed .
If the login logic is not exceeded , Judge user name 、 Is the password correct , If the password is incorrect, the threshold value will be determined , If it's over, close the darkroom , Remember that black houses have to have expiration dates , Or it will be permanently closed , This can be used redis Do it when it's overdue .
After successful login, all subsequent post logics will be performed , For example, add points ... Wait for the operation .
Mobile number registration login
flow chart :

Process description :
First, enter the mobile number , Then send it to the server , The server records the mobile number in our database , Then generate random verification code , And bind the mobile number and verification code to a redis Inside , Then record the expiration date , This expiration date is usually 10 About minutes , This is the validity period of our general mobile phone verification code .
When the mobile phone receives the SMS , Then fill in the verification code in the interface and send it to the server , After the server receives the verification code, it will be in redis Check the verification code corresponding to the mobile phone number , If it fails, it will return the error code .
Log in after success .
There doesn't seem to be a clear sign in operation , In fact, sending mobile phone number can be considered as a regular registration , Then the verification code input is a login operation ,
ask : What do I do with the password ?
answer : Add one to the follow-up product Mobile phone number password supplement function that will do , It's a very conventional technique now , But now in the era of mobile Internet explosion , Passwords are not that important anymore , Anyway, I never remember the code , If the phone number can be operated app, Never use a password to operate .
Database design
Table structure :
Self increasing ID | user name | password | cell-phone number | Wrong number |
1 | user1 | 7fef6171469e80d32c0559f88b377245 | 13456789012 | 0 |
2 | user2 | 7fef6171469e80d32c0559f88b377245 | 13456789013 | 0 |
explain :
Here is just the data needed , There is no extension of specific scenarios , This table structure can satisfy the design of the above two schemes .
Introduce third party account scheme
Here is to QQ-SDK Login logic , Let's start with a sequence diagram

explain :
The client calls up the login interface , Enter the user name 、 password , Here is the user name of the third party , password , After successful login , Returns the access_token openid expire_in, This process will use oauth2.0, But in the sdk The built-in callback gets , Later we will explain what we have achieved oauth2.0
The client gets access_token、openid、login_type(qq、wechat...) Request application server , After the application server gets these data, it will follow the corresponding login_type Go to the corresponding user center access_token and openid check . If the verification fails, the corresponding error code will be returned
After passing the verification, it will determine whether there is this in the local area login_type and openid Whether there is , If it doesn't exist, get the remote user name 、 Basic information such as avatars is used as local basic data , And back to code value
If it already exists , That is to log in , return code value .
The client gets code After value token Value in exchange for , This is in full compliance with oauth2.0 The agreement came and went , Every subsequent request must be accompanied by token,token It takes a long time to be on the server , Because what we want to do is the kind of operation that never goes offline , So every time we ask, we will token The expiration time is accumulated .
Database design
According to the suggestions of some of our partners , I'm here to do some database sorting :
User base table (users)
Field | remarks |
user_id | user id |
token | Users log in token |
expire_in | token Expiration time |
try_times | Number of login failures |
User authentication association table (user_auth_rel)
Field | remarks |
id | Self increasing id |
user_id | user id |
auth_id | Validation form id |
auth_type | Verification type (local、third) |
Local user table (user_local_auth)
Field | remarks |
auth_id | authentication id, Self increasing id |
user_name | User unique identification |
password | User password |
mobile | User's mobile phone |
Third party user list (user_third_auth)
Field | remarks |
auth_id | user id |
openid | Third party user unique ID |
login_type | Third party platform logo (qq、wechat...) |
access_token | Acquired by a third party access_token, Verification use |
explain
users The table is only for the login of our business side , Mainly do their own business oauth2.0 Business
user_local_auth Make your own user name 、 Password to login , Mobile number login information record ,
user_third_auth It is the data record of our third-party user system ,
user_auth_rel It's used to connect us users Table and user_local_auth、user_third_auth.
The whole design concept is to distinguish self built users from third parties in storage , This also makes sense in the evolution of Architecture , At the beginning, most user systems were built by themselves , Then it's external access .
summary
In general , The access technology of the third-party users is relatively simple , There is one more design here user_thirds It can support enough third-party access , Of course, we usually log in two or three times , Too many logins are not only self maintenance costs , The interface doesn't look good, either .
I hope you can learn from the above , Be able to have a better understanding of our multi account login , Here the design does not include sub table sub database 、 No service , It's simple and direct design , Of course, the number of users is not the same as what they need , On this basis, we need to add a lot of things , Thank you for reading !
边栏推荐
- Intelligent fish tank control system based on STM32 under Internet of things
- Notes_ Vlan
- Analysis of tcpdump packet capturing kernel code
- leetcode1863_2021-10-14
- Please open online PDF carefully
- 多线程收尾
- 【Camera基础(一)】Camera摄像头工作原理及整机架构
- Memcached comprehensive analysis – 2 Understand memcached memory storage
- Wireshark packet capturing skills summarized by myself
- Web project deployment
猜你喜欢

Volcano成Spark默认batch调度器

多路转接select

如何做到全彩户外LED显示屏节能环保

About transform InverseTransformPoint, transform. InverseTransofrmDirection

Introduce the overall process of bootloader, PM, kernel and system startup

【论】A deep-learning model for urban traffic flow prediction with traffic events mined from twitter

Volcano becomes spark default batch scheduler

传输层 udp && tcp

煮茶论英雄!福建省发改委、市营商办领导一行莅临育润大健康事业部交流指导

Li Kou daily question - day 26 -496 Next larger element I
随机推荐
Memcached full profiling – 1 Fundamentals of memcached
socket done
Blender's simple skills - array, rotation, array and curve
SAP接口debug设置外部断点
虚拟机CentOS7中无图形界面安装Oracle(保姆级安装)
memcached全面剖析–3. memcached的删除机制和发展方向
Analysis of tcpdump packet capturing kernel code
滤波数据分析
【论】Deep learning in the COVID-19 epidemic: A deep model for urban traffic revitalization index
福建省发改委福州市营商办莅临育润大健康事业部指导视察工作
Analyse complète Memcached – 2. Comprendre le stockage de mémoire pour Memcached
EditText controls the soft keyboard to search
关于Unity中的transform.InverseTransformPoint, transform.InverseTransofrmDirection
The most important thing at present
Advanced secret of xtransfer technology newcomers: the treasure you can't miss mentor
PKI notes
socket(2)
Slider controls the playback progress of animator animation
02---纵波不可能产生的现象
【产品设计研发协作工具】上海道宁为您提供蓝湖介绍、下载、试用、教程