WebSoket-based login restriction method and system

Through the login restriction method based on WebSocket and Redis, the problem of poor adaptability of user account login policies in electronic office systems is solved, flexible management and control of multi-terminal login is realized, and the security and user experience of the system are improved.

CN119094510AInactive Publication Date: 2024-12-06SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411240098.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-05
Publication Date
2024-12-06
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The login restriction policy of user accounts in existing electronic office systems is difficult to adapt to the needs of different scenarios, resulting in reduced system security and ease of use, and the login situation of the same account on different terminals cannot be effectively controlled.

Method used

Using the login restriction method based on WebSocket and Redis, the terminal status is monitored through the WebSocket connection and a message channel is created in Redis, to realize the reception and sending of messages in the account, and to process login requests according to the login policy, including unlimited, squeezed out login and requested login Mode, using Redis's channel function and WebSocket's real-time communication function to achieve flexible management and control of user login status.

Benefits of technology

It improves the security and user experience of the system, realizes flexible management and control of multi-terminal login, and ensures the security of the account and the accuracy of the login status.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119094510A_ABST
    Figure CN119094510A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of electronic information systems, in particular to a websoket-based login limiting method and system, and the method comprises the following steps: receiving an account number and a password input by a user, and sending a login request to a server; the server obtains a login strategy of the user account and verifies the account and the password; if the verification is successful, establishing a WebSocket connection to monitor the connection state of the terminal, and creating or connecting to a corresponding message channel for the account in the Redis to realize message receiving and sending in the account; processing a login request of the account according to the login strategy, wherein the login request comprises unlimited login, extrusion login and application login modes; the method and the system have the beneficial effects that the websocket, the redis and the like are adopted, the main function of the websocket is to realize the link and message interaction with the login terminal so as to realize the login request during login with the same account, and the main function of the redis is to realize the storage of the login token and the message broadcast between the accounts so as to realize the login limitation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of electronic information systems, and in particular to a login restriction method and system based on websoket. Background Art

[0002] With the rapid development of computer technology, the security of user accounts in electronic office systems has increasingly higher requirements. During the system construction process, in order to control the number of account logins, technical personnel usually impose login restrictions on user accounts.

[0003] Account login policies can be configured for different scenarios. For example, the same account can be logged in at different terminals at the same time. The same account is only allowed to log in at one terminal at the same time. The processing strategies include direct elimination mode and consultation mode. However, there is a problem in the controllable number of terminals for user accounts to be online at the same time in the information system, which makes it difficult to adapt to different login requirements for different accounts in the system, reducing the security and usability of the system. Summary of the invention

[0004] The purpose of the present invention is to provide a login restriction method and system based on websoket to solve the problems raised in the above background technology.

[0005] To achieve the above object, the present invention provides the following technical solution: a login restriction method based on websoket, the method comprising the following steps:

[0006] Receive the account and password entered by the user and send a login request to the server;

[0007] The server obtains the login policy of the user account and verifies the account and password;

[0008] If the verification is successful, a WebSocket connection is established to monitor the terminal connection status, and a corresponding message channel is created or connected to the account in Redis to enable the reception and sending of messages within the account;

[0009] Process account login requests according to login policies, including unrestricted login, squeezed login, and application login modes.

[0010] Preferably, the method further comprises the following steps:

[0011] When the login policy is the squeeze login mode, if the user chooses to squeeze out the logged-in account, the server clears the token of the logged-in account stored in Redis, broadcasts a forced offline message to the logged-in account through the message channel, and then allows the new account to log in and generate a new login token.

[0012] Preferably, the method further comprises the following steps:

[0013] When the login policy is the application login mode, the server sends a login application message to the logged-in account through the message channel;

[0014] The logged-in account chooses to agree or reject the login application based on the user's operation;

[0015] If you choose to agree, the logged-in account will automatically log out and clear the login token in Redis, and the new account will continue the login process; if you choose to reject, the new account login request will fail.

[0016] Preferably, the method further comprises the following steps:

[0017] After successful login, the server generates a login token for the corresponding account and stores it in the Redis cache database;

[0018] Maintain the WebSocket connection and perform heartbeat detection to monitor the connection status. If a disconnection is detected, the corresponding login token in Redis is automatically cleared.

[0019] Preferably, the method utilizes the channel function of Redis to realize the propagation of messages within the same account, and realizes the connection status monitoring between the server and the client through the real-time communication function of WebSocket, thereby realizing flexible management and control of the user login status, and improving the security of the system and the user experience.

[0020] A login restriction system based on websoket, comprising a user login module, a cache database module, a message channel module and a real-time communication module;

[0021] User login module, used to receive the user's login request, including the user name and password, and perform verification;

[0022] The cache database module, specifically redis, is used to store the user's login token and online status information to support synchronization and query of multi-terminal login status;

[0023] The message channel module uses the channel function of redis to realize message broadcasting and synchronization between different terminals under the same account;

[0024] The real-time communication module uses websocket technology to achieve real-time connection and status monitoring between the server and the client, and is used to detect changes in connection status and perform corresponding login token management operations.

[0025] Preferably, the user login module further includes a policy acquisition unit, which is used to acquire a corresponding login restriction policy according to the user account, and determine whether a multi-terminal login management operation needs to be performed according to the policy.

[0026] Preferably, the cache database module further includes a token management unit, which is used to generate a login token and store it in redis when the user logs in, and to clear the corresponding login token when the user logs out or a multi-terminal login conflict occurs, and broadcast a corresponding notification message through the message channel module.

[0027] Preferably, the message channel module includes a message sending unit and a message receiving unit, wherein:

[0028] A message sending unit, used to send a login application or a forced offline notification message to a logged-in terminal;

[0029] The message receiving unit is used to receive a response message from a logged-in terminal and perform corresponding login processing operations according to the response content, such as allowing login, refusing login or performing a logout operation.

[0030] Preferably, the real-time communication module also includes a heartbeat detection unit for periodically detecting the active state of the websocket connection, and when a disconnection is detected, clearing the corresponding login token through the cache database module to ensure the accuracy and security of the system login state.

[0031] Compared with the prior art, the present invention has the following beneficial effects:

[0032] The websocket-based login restriction method and system proposed in the present invention adopt websocket, redis, etc. The main function of websocket is to realize the link and message interaction with the login terminal, and then realize the login request when logging in with the same account. The main function of redis is to realize the storage of login tokens and the message broadcasting between accounts, and then realize login restriction. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] Figure 1 The figure is a flow chart of the method of the present invention. DETAILED DESCRIPTION

[0034] In order to make the purpose and technical solution of the present invention clearly and completely described, and the advantages more clearly understood, the embodiments of the present invention are further described in detail with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are part of the embodiments of the present invention, rather than all of the embodiments, and are only used to explain the embodiments of the present invention, and are not used to limit the embodiments of the present invention. All other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0035] For example, see Figure 1 The present invention provides a technical solution: a login restriction method based on websoket, comprising:

[0036] This login restriction method uses redis to store the login token of the account and implement the channel broadcast of the login message, and uses websocket to connect the account and the message channel. Using the cache database redis to store the login token generated by the user can reduce the transmission of key information and improve the efficiency of request access. At the same time, it is convenient to count the number of online users to determine whether there is a logged-in terminal; using the channel function of redis to enable the same account to monitor the same message channel, it is convenient for the message propagation between the same account; using the real-time communication function of websocket, it is possible to monitor the connection status between the server and the page, which is convenient for clearing the disconnected account.

[0037] When an account initiates a login request on the login page, the login restriction policy of the corresponding account is obtained first. After completing the account and password verification, if the redis channel of the account exists, a channel connection corresponding to the account is established. If it does not exist, a channel is created and a connection is established. If it is a single account login restriction policy, query whether the account has a token stored in the cache database. If not, directly perform password login verification and return the login token; if it exists and is a forced login policy, choose whether to force login or cancel login according to the login prompt. For forced login, the login token stored in the cache database of the account is cleared and a message of account being squeezed out is sent to the message channel; if it is a login application policy, a message is sent and waits for the terminal of the logged-in account to feedback whether to allow login. If the online terminal chooses to agree, a broadcast message is sent to the channel and the current terminal is exited. If it does not agree, the logged-in terminal remains logged in. The request initiator receives a message of login rejection from the message channel, and this login fails.

[0038] This technical solution is different from other account login restriction implementation solutions. This solution can configure and implement multiple login strategies through system parameter settings, while other technical solutions are too single in implementation and the message interactivity within the same account is poor.

[0039] This solution adopts storage based on cache database redis and real-time communication of redis message channel and websocket, so this solution has the function of synchronous cache, that is, switching login terminal, login device or clearing cache, login restriction is still valid, and websocket is used to synchronize the disconnected terminal to clear the login token operation.

[0040] The steps of the above scheme are as follows:

[0041] Step 1: Enter the account and password to send a login request, obtain the user policy in the background, and connect to the websocket server if the username and password are successfully verified. Monitor the terminal connection status, and establish a corresponding message channel in the redis channel and monitor it to receive and send messages within the account. Then, proceed to step 2.

[0042] Step 2: If the policy does not restrict login, execute step 5. If there is a login restriction and there is a terminal that has already logged in (determine whether there is a logged-in terminal based on the number of tokens stored in redis), it is necessary to determine the login processing mode: squeeze out login (execute step 3), apply for login (execute step 4);

[0043] Step 3: If the login mode is to be squeezed out, a prompt box will pop up on the login page for the user to choose to squeeze out the login or cancel the current login. If the user chooses to cancel the login, the process returns to step 1. If the user chooses to squeeze out the login, the token stored in the cache database will be cleared and a forced offline message will be broadcast to the message channel, and then step 5 will be executed.

[0044] Step 4: If it is the application mode, a request message for applying for login is sent to the logged-in terminal through the message channel. If the logged-in terminal chooses to agree, the logged-in terminal automatically executes the logout operation and clears the stored login token in the cache database, and the applicant continues to execute step 5; if it chooses to refuse, the logged-in terminal remains logged in, and the applicant executes step 1;

[0045] Step 5: If the user logs in successfully, a corresponding login token is generated and stored in the cache database, and the connection with the websocket server is maintained while performing heartbeat detection.

[0046] Embodiment 2, based on embodiment 1, proposes a login restriction system based on websoket, including a user login module, a cache database module, a message channel module and a real-time communication module;

[0047] The user login module is used to receive the user's login request, including the user name and password, and verify it; the user login module also includes a policy acquisition unit, which is used to obtain the corresponding login restriction policy according to the user account, and determine whether it is necessary to perform multi-terminal login management operations based on the policy.

[0048] The cache database module, specifically redis, is used to store the user's login token and online status information to support synchronization and query of multi-terminal login status; the cache database module further includes a token management unit, which is used to generate a login token when the user logs in and store it in redis, and when the user logs out or a multi-terminal login conflict occurs, clear the corresponding login token and broadcast the corresponding notification message through the message channel module.

[0049] The message channel module uses the channel function of redis to realize message broadcasting and synchronization between different terminals under the same account; the message channel module includes a message sending unit and a message receiving unit, where:

[0050] A message sending unit, used to send a login application or a forced offline notification message to a logged-in terminal;

[0051] The message receiving unit is used to receive a response message from a logged-in terminal and perform corresponding login processing operations according to the response content, such as allowing login, refusing login or performing a logout operation.

[0052] The real-time communication module uses websocket technology to achieve real-time connection and status monitoring between the server and the client. It is used to detect changes in connection status and perform corresponding login token management operations. The real-time communication module also includes a heartbeat detection unit, which is used to periodically detect the active status of the websocket connection and clear the corresponding login token through the cache database module when a disconnection is detected, to ensure the accuracy and security of the system login status.

[0053] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. A login restriction method based on websoket, characterized in that: The method comprises the following steps: Receive the account and password entered by the user and send a login request to the server; The server obtains the login policy of the user account and verifies the account and password; If the verification is successful, a WebSocket connection is established to monitor the terminal connection status, and a corresponding message channel is created or connected to the account in Redis to enable the reception and sending of messages within the account; Process account login requests according to login policies, including unrestricted login, squeezed login, and application login modes.

2. According to a websoket-based login restriction method according to claim 1, it is characterized in that: The following steps are also included: When the login policy is the squeeze login mode, if the user chooses to squeeze out the logged-in account, the server clears the token of the logged-in account stored in Redis, broadcasts a forced offline message to the logged-in account through the message channel, and then allows the new account to log in and generate a new login token.

3. According to a websoket-based login restriction method according to claim 1, it is characterized in that: The following steps are also included: When the login policy is the application login mode, the server sends a login application message to the logged-in account through the message channel; The logged-in account chooses to agree or reject the login application based on the user's operation; If you choose to agree, the logged-in account will be automatically logged out and the login token in Redis will be cleared, and the new account will continue the login process; If you choose to reject, the new account login request will fail.

4. A websoket-based login restriction method according to claim 3, characterized in that: The following steps are also included: After successful login, the server generates a login token for the corresponding account and stores it in the Redis cache database; Maintain the WebSocket connection and perform heartbeat detection to monitor the connection status. If a disconnection is detected, the corresponding login token in Redis is automatically cleared.

5. A websoket-based login restriction method according to claim 1, characterized in that: The method utilizes the channel function of Redis to realize the propagation of messages within the same account, and realizes the connection status monitoring between the server and the client through the real-time communication function of WebSocket, thereby realizing flexible management and control of the user login status, and improving the security of the system and the user experience.

6. A websoket-based login restriction system according to the websoket-based login restriction method according to claim 1, comprising a user login module, a cache database module, a message channel module and a real-time communication module, characterized in that: User login module, used to receive the user's login request, including the user name and password, and perform verification; The cache database module, specifically redis, is used to store the user's login token and online status information to support synchronization and query of multi-terminal login status; The message channel module uses the channel function of redis to realize message broadcasting and synchronization between different terminals under the same account; The real-time communication module uses websocket technology to achieve real-time connection and status monitoring between the server and the client, and is used to detect changes in connection status and perform corresponding login token management operations.

7. A websoket-based login restriction system according to claim 6, characterized in that: The user login module also includes a policy acquisition unit, which is used to acquire a corresponding login restriction policy according to the user account, and determine whether a multi-terminal login management operation needs to be performed according to the policy.

8. A websoket-based login restriction system according to claim 6, characterized in that: The cache database module further includes a token management unit, which is used to generate a login token and store it in redis when a user logs in, and to clear the corresponding login token when a user logs out or a multi-terminal login conflict occurs, and broadcast a corresponding notification message through the message channel module.

9. A websoket-based login restriction system according to claim 6, characterized in that: The message channel module includes a message sending unit and a message receiving unit, wherein: A message sending unit, used to send a login application or a forced offline notification message to a logged-in terminal; The message receiving unit is used to receive a response message from a logged-in terminal and perform corresponding login processing operations according to the response content, such as allowing login, refusing login or performing a logout operation.

10. A websoket-based login restriction system according to claim 6, characterized in that: The real-time communication module also includes a heartbeat detection unit, which is used to periodically detect the active status of the websocket connection, and when a disconnection is detected, clear the corresponding login token through the cache database module to ensure the accuracy and security of the system login status.

Citation Information

Patent Citations

  • Information sending and receiving method and device, server, client, and storage medium

    CN109587249A

  • Head-mounted display device single sign-on method and system based on virtual reality

    CN113923010A

  • Dynamic data source synchronization method under cluster and micro service

    CN118568173A

  • Device id-based login state sharing method and device

    WO2020155492A1