当前位置:网站首页>Talk about the principle of QR code scanning login
Talk about the principle of QR code scanning login
2022-06-11 14:57:00 【Ant】
Talk about the principle of QR code scanning and login
In daily life, there are a lot of scenes of scanning QR code , Recently, I happened to see videos and articles about this , Learn about the technology and logic behind the QR code .
One of the most commonly used scenarios for two-dimensional code is scanning through mobile applications PC perhaps WEB The end of the QR code , To log in to the same system .
For example, mobile wechat scan code login PC End wechat , Mobile Taobao scan code login PC Taobao . So let's take a look at , How does QR code login work !
The essence of QR code login
In essence, QR code login is also a way of login authentication .
There are two things you need to do for regular login authentication :
- Tell the system who I am
- Prove to the system who I am
By scanning the QR code , Transfer the account information of mobile phone to PC End , Prove to the system who I am .
Mobile terminal APP It's already logged in , That is to say, the mobile terminal has passed the login authentication . as long as Scan the code to confirm that the mobile phone is operated by this account , In fact, it can indirectly prove who I am .
QR code
First, let's get to know the QR code , Before we know two-dimensional code, let's take a look at one-dimensional code , Also known as bar code : One dimensional bar code
One dimensional code , That's the bar code , Bar codes in supermarkets – I believe everyone is very familiar with this , A bar code is actually a string of numbers , It stores the serial number of the product .
Two dimensional code is similar to bar code , It's just that it doesn't store numbers , It can also be any string , You can think , It's just another representation of strings .
System authentication mechanism
For the sake of safety , It will not store your login password on the mobile terminal . But in daily use , We should have noticed , Only after your app is downloaded , The first time I log in , You need to log in with an account and password , After that Even if the application process is killed , Or the phone restarts , There is no need to re-enter the account password , It can log in automatically .
be based on token Authentication mechanism of :
- Account password login , The client will pass the device information to the server ,
- If the account and password pass the verification , The server will bind the account to the device , In a data structure , This data structure contains accounts ID, equipment ID, Equipment type, etc
const token = {
acountid:' account number ID',
deviceid:' Login device ID',
deviceType:' Device type , Such as iso,android,pc......',
}Then the server will generate a token, Use it to map data structures , This token It's actually a string of strings with a special meaning , The point of it is , You can find the corresponding account and device information through it .
- The client gets this token after , You need to do a local save , Every time you visit the system API Take them with you token And device information .
- The server can use token Find the account and device information bound to it , Then compare the bound device information with the device information sent by the client each time , If the same , So the verification passed , return AP Interface response data , If different , That is, the verification fails and access is denied
The client doesn't and doesn't need to save your password , contrary , It's preserved token. Maybe some students will think , This token So important , What if someone else knows . actually , It doesn't matter if I know , Because device information is unique , As long as your device information is unknown to others , Other people use other devices to access , The verification also failed .
The purpose of client login , That is to get what belongs to you token.
Scan QR code login general steps :
- Before scanning code , The mobile app is logged in ,PC There's a QR code on the end , Waiting for the scan
- Open the app on the mobile terminal , scanning PC The end of the QR code , After scanning , Will prompt ” Scanned , Please click "confirm" on the mobile phone ”
- The user clicks "confirm" on the mobile terminal , After the confirmation PC The end login is successful
You can see , The QR code has three states in the middle , To be scanned , Scanned for confirmation , Confirmed .
- There must be a uniqueness behind the two-dimensional code ID, When the QR code is generated , This ID It's also generated together , And bound PC The device information of the terminal
- Mobile phone to scan this QR code
- The QR code switches to Status scanned for confirmation , At this point, the account information will be associated with this ID binding
- When the mobile terminal confirms the login , It will generate PC End for login token, And return it to PC End
The specific process :
QR code preparation
According to different states of QR code , The first is waiting for the scan state , User opens PC End , When switching to the QR code login interface .
- PC The client sends a request to the server , Tell the server , I want to generate the QR code of user login , And the PC The end device information is also transmitted to the server
- After the server receives the request , It generates a two-dimensional code ID, And the QR code ID And PC The end device information is bound
- And then put the QR code ID Return to PC End
- PC The terminal receives the QR code ID after , Generate qr code ( The QR code must contain ID)
- In order to know the status of the QR code in time , After the client shows the QR code ,PC The server keeps polling the server , Like polling every second , Request the server to tell the status and related information of the current QR code
Scan state switch
- Users use their mobile phones to scan PC The end of the QR code , Get the QR code from the QR code ID
- Then call the server API Combine the identity information of mobile terminal with two-dimensional code ID Send it to the server together
- After the server receives it , It can combine identity information with two-dimensional code ID Binding , Generate temporary token. And then back to the phone
- because PC The client has been polling the QR code status , So at this time, the state of the QR code changes , It can update the QR code status to scanned on the interface
temporary token For the next operation of the mobile terminal , You can use it as a voucher . To make sure you scan the code , The two steps of login are sent from the same mobile terminal .
Status confirmation
- The mobile terminal receives the temporary token After that, the login confirmation interface will pop up , When the user clicks confirm , Mobile phones carry temporary token The interface used to call the server , Tell the server , I have confirmed
- After the server receives the confirmation , According to the QR code ID Bound device information and account information , Generate users PC End login token
- Now PC The polling interface at the end , It can tell that the state of the QR code has become ” Confirmed ”. And you can get the login information from the server token
- Come here , Login is successful , Back end PC You can use token To access the resources of the server
summary
We trigger from the nature of landing , Explore how QR code scanning login works
- Tell the system who I am
- Prove to the system who I am
In the process , Let's talk about two premises first ,
- One is the principle of two-dimensional code ,
- One is based on
tokenAuthentication mechanism of .
And then we take the QR code status as the axis , The logic behind this is analyzed : adopt token Authentication mechanism and two-dimensional code state change to achieve code scanning login .
It's important to point out that , The login process mentioned above , It applies to the same system PC End ,WEB End , Mobile .
Reference material
- TikTok Two sides :“ Talk about the principle of QR code scanning and login ”.
- Classmate Dagu
- Geek time, a QR code video
Sharing plans
Blog content will be synchronized to Tencent cloud + Community , Invite everyone to join us :https://cloud.tencent.com/
license agreement
In this paper A signature - Noncommercial use - Share in the same way 4.0 The international license agreement , Reprint please indicate the source .
边栏推荐
- Nomad application layout scheme 04 of hashicopy (scaling and updating a job)
- Lippon instrument software intern interview
- NVIDIA R & D director: how does AI improve chip design?
- In depth research and analysis report on global and Chinese SURFBOARD WAX Market
- 111. minimum depth of binary tree
- 一些经典的嵌入式C面试题汇总
- 数据库优化
- Riskscanner of multi Cloud Security compliance scanning platform
- I have something to say about final, finally and finalize
- one hundred and twenty-three thousand four hundred and sixty-five
猜你喜欢

Illustration of tiger international quarterly report: revenue of USD 52.63 million continued to be internationalized

树莓派获得网络安装系统功能,无需借助其他设备

Tencent interviewers share their interview experience, how to evaluate the interviewers' technical and personal comprehensive quality, and give you some suggestions on the interview
![[SystemVerilog interface] ~ interface](/img/dc/0a9750cace1460af772e2f3f6a8763.png)
[SystemVerilog interface] ~ interface

Webgl programming guide learning (0)

Uniapp settings page Jump effect - navigateto switching effect - Global animationtype animation

数据库优化
![[verification of SystemVerilog] ~ test platform, hardware design description, excitation generator, monitor and comparator](/img/3a/0cc26400eeb4b388face09b9a10f27.png)
[verification of SystemVerilog] ~ test platform, hardware design description, excitation generator, monitor and comparator

【Azure 应用服务】NodeJS Express + MSAL 实现API应用Token认证(AAD OAuth2 idToken)的认证实验 -- passport.authenticate()

Cisco Rui submitted the registration of sci tech Innovation Board: proposed to raise 600million yuan, with annual revenue of 222million yuan
随机推荐
简单的C语言版本通讯录
Hashicopy之nomad应用编排方案05(访问web页面)
Lippon instrument software intern interview
百度某离职员工跳槽字节被判赔107万元;苹果谷歌微软拟“干掉”密码;传吉利已收购魅族|Q资讯
Cisco Rui submitted the registration of sci tech Innovation Board: proposed to raise 600million yuan, with annual revenue of 222million yuan
Cartoon: interesting "cake cutting" problem
Raspberry pie obtains the function of network installation system without the help of other devices
Analyse approfondie de la conception du système relationnel du Groupe de cercles
NVIDIA R & D director: how does AI improve chip design?
Leetcode daily question - Search insertion position
Flutter 3.0 was officially released: it stably supports 6 platforms, and byte jitter is the main user
In depth research and analysis report on global and Chinese SURFBOARD WAX Market
Determine whether a string contains the specified string (verified)
深度剖析「圈組」關系系統設計 | 「圈組」技術系列文章
浅谈居家办公后的感想| 社区征文
Hashicopy之nomad应用编排方案03(运行一个job)
汤峥嵘:CTO 是商业思维和技术思维交汇的那个点
[SystemVerilog interface] ~ interface
Backtracking / solution space tree permutation tree
Ali, tell me about the application scenarios of message oriented middleware?