Source: https://juejin.im/post/5d0a298bf265da1b827aa06f
-
Preface: Multi-account login -
1. Initial stage of entrepreneurship -
2. Database design -
3. Introduction of third-party account solutions -
4. Database design -
5. Summary
Introduction: Multi-account login

- the front end sends the user name and password to the server, and the
-
server makes a regular judgment to determine whether the user name and password length are met, whether the user name is repeated, etc., and the conditions are not directly returned to the front end by directly returning the corresponding error code. Here the password field, in order to prevent the transmission process from being truncated, it is recommended to encrypt and then upload, our transmission password will be encrypted by default MD5, and then recorded to the database for another layer of encryption, even if it is out of storage, the password should not be stored in plaintext. -
After the verification is passed, the user name and password are written to the database, and subsequent operations such as point issuance are carried out, which is not expanded here. -
Now log in, the front end will send the user name and password to the server, the server will first check whether the number of logins exceeds the set threshold, if it exceeds it, you can only continue to wait for the small black room to be closed. -
If it does not exceed the logic of continuing login, judge whether the user name and password are correct, and the incorrect password will be judged by the threshold, if it exceeds the small black room, remember that the small black room must set an expiration time, otherwise it will be permanently closed, which can be done with the expiration of Redis. -
After successful login, perform all subsequent post-logic, such as adding points.
Mobile phone number registration and login
- first enter the mobile phone number, and then
-
send it to the server, the server will record the mobile phone number in our database, and then generate a random verification code, and bind the mobile phone number and verification code to a redis. Then record the expiration time, this expiration time is generally about 10 minutes, which is the validity period of our general mobile phone verification code. -
receives the mobile phone SMS, then fill in the verification code in the interface to send to the server, and the server will query the verification code corresponding to this mobile phone number in Redis after receiving the verification code, and the error code will be returned if it fails. -
After success, the login operation is performed.
After the mobile phone
2. Database design
3. Introducing a third-party account solution
- the
-
client calls up the login interface by itself, enters the user name and password, here is the third party’s user name, password, after successful login, it will return access_token openid expire_in, This process will use OAuth2.0, but the built-in callback in the SDK is obtained, and later we will explain that our own implementation of OAuth2.0 -
client gets access_token, OpenID, login_type (QQ, WeChat…) Request the application server, and after the application server gets these data, it will go to the corresponding user center for access_token and openID verification according to the corresponding login_type.
If the verification fails, the
-
after the verification is passed, it will determine whether the local login_type and openid exist, and if it does not exist, obtain the remote user name, Basic information such as avatars are used as local basic data -
already exists, it is a login operation and returns the code value. -
exchanged, which is completely in accordance with the OAuth2.0 protocol, and each subsequent request must bring the token, and the token value is on the server side for a long time, because what we want to do is the kind of operation that never goes offline, so each request we will add up the token expiration time.
, and if the code value
After the client gets the code value, the token value is
4. Database
user
- users
-
table is only for our business side login, mainly to do their own business OAuth2.0 business -
user_local_auth do their own user name, password login, The mobile phone number login information -
user_third_auth the data record of our third-party user system, -
user_auth_rel is used to associate our users table with user_local_auth and user_third_auth. -
The whole design concept is to distinguish self-built users from third parties in storage, which is also reasonable in terms of architecture evolution, at first most of the user system is self-built, and then external access.
,
record
5. To sum up
, the access technology of third-party
end
public number (zhisheng) reply to Face, ClickHouse, ES, Flink, Spring, Java, Kafka, Monitoring < keywords such as span class="js_darkmode__148"> to view more articles corresponding to keywords.
like + Looking, less bugs 👇