A random key-based authentication method, device, equipment and storage medium
By generating a random key and binding it to a unique identification ID, and using email to verify user identity, the problem of poor fault tolerance of email verification in the existing technology is solved, and flexible and secure user authority judgment is achieved.
Patent Information
- Application Number
- CN202211724189.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2042-12-30
AI Technical Summary
In the prior art, email verification cannot tolerate errors when the verification email is sent incorrectly or other problems occur, resulting in inflexible and insecure user identity verification.
A random key-based authentication method is adopted. By generating a random key and binding it to a unique identification ID, a verification link is sent via email. After the user enters the key, the background interface verifies the key status to realize user authority judgment.
It achieves flexibility and security of user identity authentication, reduces costs, avoids verification problems caused by wrong emails or user errors, and enhances the security and flexibility of the system.
Smart Images

Figure CN116015683B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to an authentication method, device, equipment and storage medium based on random keys. Background Art
[0002] With the development of mobile internet, a wide variety of backend management systems have emerged. Users often need an account and password to log in to these backends. When a password is forgotten or changed, or when registering an account, users are often required to provide an email address or mobile phone number in order to receive a verification code to verify the authenticity of the email address and the user. After the user enters the verification code, the backend verifies its authenticity and timeliness to determine whether to authorize the user to proceed with subsequent registrations, password changes, and other user actions.
[0003] Given the aforementioned technical background, verification is often facilitated by using text messages, often combined with Redis's support for data persistence. However, given the cost of sending text messages, some public welfare open source projects have abandoned this method and are instead using email verification. While email verification is also an existing method, it is notoriously difficult to tolerate errors such as sending verification emails to the wrong address or encountering other issues. Summary of the Invention
[0004] Based on the above technical problems, the present invention proposes an authentication method, apparatus, device and storage medium based on a random key, wherein the method comprises:
[0005] Trigger the form sending event, obtain the unique identification ID of the current row, use the random number algorithm to generate a random key, and send the form;
[0006] Binding the unique identification ID to the random key and setting a state value for the random key;
[0007] Add the random key and verification hyperlink to the email content in the body of the email template, and call the email sending interface to send the email to the target website;
[0008] Log in to the target website, enter a random key, and determine whether the user is an authorized user;
[0009] The random key is received, and the state of the data verification code bound to the verification hyperlink is determined.
[0010] Optionally, the use of a random number algorithm to generate a random key includes: using a randomize plug-in to generate a random key, passing two parameters to the random algorithm function randomize(params1,params2,…), namely a first parameter params1 and a second parameter params2, wherein the first parameter params1 is the type of the generated random number, and the second parameter params2 is the length of the generated random number.
[0011] Optionally, the verification hyperlink is hidden and displayed in the form of a button hyperlink, and the unique identification ID is encrypted through MD5 and then spliced into the verification hyperlink.
[0012] Optionally, the determining whether the user is an authorized user includes: if the user cannot provide a random key of a preset length, the user is determined to be an unauthorized user, and the unauthorized user cannot perform the next operation.
[0013] Optionally, the random key is received and the status of the data verification code bound to the verification hyperlink is determined, including: if the verification code status is inactivated, determining whether the random key corresponding to the unique identification ID is consistent with the database based on the unique identification ID matching interface call; if the verification code status is activated, the user is prompted to fill it in and not to fill it in again.
[0014] Optionally, the method further includes: setting a validity period of the random key, recording the current time when generating the random key and storing it in a database, and binding it with a unique identification ID.
[0015] Optionally, receiving the random key and determining the status of the data verification code bound to the verification hyperlink include: calling an interface to obtain the generation time in the database and comparing it with the current time; if the existence time of the data verification code bound to the hyperlink is greater than the set validity time, an exception is thrown, prompting that the data verification code bound to the hyperlink has expired, and the administrator is requested to resend the random key.
[0016] In a second aspect, the present application discloses an authentication device based on a random key, comprising:
[0017] The form sending module is used to trigger the form sending event, obtain the unique identification ID of the current row, generate a random key using a random number algorithm, and send the form;
[0018] A status value setting module, configured to bind the unique identification ID to the random key and set a status value for the random key;
[0019] An email sending module is used to add the random key and the verification hyperlink to the email content in the body of the email template, and call the email sending interface to send the email to the target website;
[0020] A user login module is used to log in to the target website, input a random key, and determine whether the user is an authorized user;
[0021] The verification code determination module is used to receive the random key and determine the status of the data verification code bound to the verification hyperlink.
[0022] In a third aspect, the present application discloses an electronic device, comprising:
[0023] Memory, used to store computer programs;
[0024] A processor is configured to execute the computer program to implement the random key-based authentication method.
[0025] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program, which implements the random key-based authentication method when executed by a processor.
[0026] Beneficial effects: The present invention generates a random key and binds it to the corresponding data on the backend, and sends it to the user who needs to be authorized via email, SMS or other media. When the user receives the key carried in the input information of the corresponding key login preset verification backend page, the key result carried in the backend interface verification information is called to notify the frontend page whether to authorize the current user to proceed to the next step, thus realizing a complete closed-loop process from user identification to authorization. The user and key are bound by building a simple service internally, and the verification function is realized by adding, deleting, modifying and checking. The implementation cost is relatively low, and more business logic can be flexibly added after the verification step. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments, and the above and / or other advantages of the present invention will become more apparent.
[0028] Figure 1 It is a flowchart of the steps of the authentication method based on random keys of the present invention.
[0029] Figure 2 It is a framework flow chart of the authentication method based on random keys of the present invention. DETAILED DESCRIPTION
[0030] In the existing technology, the email verification and authentication method cannot deal with the problem of incorrect email delivery or other possible problems. Therefore, by building a simple service internally, users and keys can be bound, and the verification function can be realized through simple additions, deletions, modifications and queries. The implementation cost is relatively low, and more business logic can be flexibly added after the verification step.
[0031] like Figure 1 、 2 As shown, this embodiment provides an authentication method based on a random key, comprising the following steps:
[0032] S101, triggering a form sending event, obtaining the unique identification ID of the current row, generating a random key using a random number algorithm, and sending the form.
[0033] Specifically, in this embodiment, the form sending function button is clicked. The form can be an onboarding form, an interview form, or other forms that can be sent by email. After clicking the form sending function button, the form sending operation is triggered. At this time, the front-end event can obtain the unique identification ID of the current row and generate a string of random keys using a random number algorithm.
[0034] Specifically, in order to prevent subsequent verification from being attacked and cracked, a string of 8 to 10-digit random keys is usually generated. This embodiment uses a randomize plug-in to generate a random key. Specifically, two parameters are passed to the randomize(params1, params2, ...) function. Params1 is the type of random number generated. In this embodiment, the input is 'Aa0', which means that the generated type is a number or uppercase and lowercase letter mode. The random combination range is 0 to 9 and A to Z, a set of a to z, which ensures the randomness of the data. Params2 is the length of the generated random number. The present invention uses 10 bits.
[0035] S102: Bind the unique identifier to the random key, and set a status value for the random key.
[0036] In this embodiment, the backend database binds a unique identification ID to a random key and sets a status value for the random key so that it can be determined whether the random key has been verified or not during subsequent verification. In the present invention, the status value indicates whether the key has been verified. It is generally set to a Boolean value, represented by checkResult, and defaults to false, i.e., not verified. When the key is entered by the user and the verification interface is called, if it is consistent with the key bound to the current data, the value is changed to true, indicating that the verification is successful; otherwise, it remains false. When the user subsequently logs in to verify the key within the validity period, the status value can be matched. If the value is true, the user is prompted that the key has been verified. Here, the user can be prompted to proceed to the next step according to business needs, or prompted that the key has been verified and cannot be used further. If the value is false, subsequent verification will continue.
[0037] S103: Add the random key and the verification hyperlink to the email content in the body of the email template, and call the email sending interface to send the email to the target website.
[0038] In this embodiment, a random key is added to the email content in the body of the email template, and a target website is provided. The target website can be a link to a website for backend registration or random key verification. The email is then sent to the target website by calling the email sending interface. To ensure website security, the present invention hides the verification link and displays it as a button hyperlink, thus preventing the plaintext verification backend address from being exposed to the user. At the same time, this step also requires the unique identification ID to be encrypted with MD5 and then spliced into the hyperlink, so that the corresponding random key and some basic information of the employee to be hired can be found later through the unique identification ID.
[0039] S104, log in to the target website, enter a random key, and determine whether the user is an authorized user.
[0040] In this embodiment, when a user receives an email, for example, a new employee who is about to join the company receives an email, he can click a button according to the content of the email to enter the pre-set website backend page. At this time, a pop-up box for entering a verification code will pop up, requiring the input of a random key generated in the email to determine whether the current user is the recipient of the email. Users who cannot provide the preset length can be judged as unauthorized users and cannot be authorized to proceed to the next step. Users who enter a random key that matches successfully can proceed to the next step.
[0041] S105, receiving the random key, determining the status of the data verification code bound to the verification hyperlink, and if the verification code status is inactive, determining whether the random key corresponding to the unique identifier is consistent with that in the database based on the unique identifier matching interface call; if the verification code status is activated, prompting the user.
[0042] After the user enters the random key in the email, the following processing steps are divided into two categories: one is to call the backend interface to compare the random key bound to the ID of this hyperlink with the database to see if it matches; the other is to first verify whether the verification code status in the data bound to this hyperlink has been activated. The two situations are as follows:
[0043] In this embodiment, for the first method, if the status is unverified, verification is performed. If the comparison is correct, the verification status of the data is changed to activated or verified. It should be emphasized that when performing email verification, the user needs to enter the email address provided to the sender and the random key. Only when the two correspond to each other can the verification be passed and the verification code status is changed to activated or verified.
[0044] In this embodiment, for the second method, if the random key status corresponding to the ID in the database is activated or verified, it means that the employee has already filled in the employment information, or verified the random key in the email, then the user is prompted not to fill in the information again since he has already filled in the information, so as to avoid the user from filling in the data again.
[0045] In addition to the above embodiments, the present invention has other embodiments in order to optimize the above embodiments.
[0046] In this embodiment, the present invention proposes a method for dealing with the problem of incorrect email sending. If the email fails to be sent or the user's mailbox is entered incorrectly and needs to be changed in the background, the email can be resent. After the administrator changes the user's mailbox, you can click the resend button on the page to regenerate a new random key and set the status to inactivated or unverified. This avoids the problem that if the mailbox is wrong, the original wrong mailbox may be used by others to cause information leakage after receiving the email. Generating a new random key to replace the original random key can solve this problem.
[0047] In this embodiment, the present invention proposes an optimization step. In order to further improve security, the validity period of the random key is set, and the random key is valid within the specified time. The specific implementation method is as follows: when generating the random key, the current time is recorded and saved in the database and bound to the unique identifier id. The subsequent verification step of whether it is expired is the same as S105. The interface is called to obtain the generation time in the database and compare it with the current time. If the data verification code bound to the hyperlink exists for a time greater than the set time, an exception is thrown, prompting the administrator to resend the random key if the verification code expires. This step can be executed before verifying the random key (S105). If it expires, no subsequent verification will be performed, saving server resources.
[0048] In this embodiment, the validity period is usually 5 minutes, 1 hour or one day. Of course, other validity periods that can be implemented in this embodiment can be determined according to business conditions. The complete implementation process is to record the current time when the random key is generated in the background as the start time of the validity period. When the user initiates the test, the current time is recorded as the comparison time. The comparison time is subtracted from the start time. If it is within the set range, it is valid, otherwise it is expired or invalid time.
[0049] The present invention proposes an authentication method based on a random key, which generates a random key and binds it to the corresponding data of the backend, and sends it to the user who needs to be authorized through email, text message or other media. When the user receives the key carried in the input information of the corresponding key login preset verification backend page, the key result carried in the backend interface verification information is called to notify the frontend page whether to authorize the current user to proceed to the next step, thereby realizing a complete closed-loop process from user identification to authorization. The present invention can realize the binding of users and keys by building a simple service internally, and can realize the verification function by simple addition, deletion, modification and query, with relatively low implementation cost and high security. At the same time, more business logic can be flexibly added after the verification step, and the random algorithm is used to further increase the security of the system. The code docking and implementation are relatively easy, and the problem of delayed or unreceived verification code is avoided.
[0050] Furthermore, the embodiment of the present application also discloses an authentication device based on a random key, comprising:
[0051] The random key generation module is used to send the form. It first obtains the unique ID of the current row and generates a random key using a random number algorithm.
[0052] The status value setting module is used in the background database to bind the unique identification ID with the random key and set a status value for the random key, which is used to determine whether the random key has been verified or not during subsequent verification;
[0053] The hyperlink generation module is used to generate a hyperlink, specifically including: calling the email sending interface, writing the random key into the email content in the body of the email template, and providing a link to the website for backend registration or verification of the random key;
[0054] The verification module is used when a user receives an email and clicks a button according to the email content to enter a pre-set website backend page. At this time, a pop-up box for entering a verification code will pop up, requiring the input of a random key generated in the email to confirm whether the current user is the email recipient. Users who cannot provide a random key of the preset length will be judged as invalid users and will not be authorized to proceed to the next step. When the user enters the random key carried in the email, the backend interface is called to compare whether the random key bound to the hyperlink ID is consistent with the database, or to first verify whether the verification code status in the data bound to the hyperlink has been activated;
[0055] The backend management module is used to resend emails when email sending fails or user mailbox entry errors require backend changes, resend emails after the administrator changes the user mailbox, regenerate a new random key and set the status to inactivated or unverified.
[0056] Furthermore, the random key generation module uses the randomize plug-in to generate a random key, and passes two parameters params1 and params2 to the randomize(params1, params2, ...) function, where params1 is the type of the generated random number and params2 is the length of the generated random number;
[0057] Furthermore, the hyperlink generation module hides the verification link and displays it in the form of a button hyperlink, encrypts the unique identification ID through MD5 and then splices it into the hyperlink;
[0058] Furthermore, the verification module is divided into the following two situations during verification:
[0059] In the first case, if the status is unverified, verify it. If the comparison is correct, change the verification status of the data processed in the current row to activated or verified.
[0060] In the second case, if the random key status corresponding to the unique identification ID in the database is activated or verified, it means that the user has already filled in the information, or verified the random key in the email, then the user will be prompted to fill in the information and not to fill it in again.
[0061] Furthermore, the device also includes a valid time setting module for setting the valid time of the random key. When generating the random key, the current time is recorded and saved in the database, and at the same time bound to the unique identification ID. The subsequent verification of whether it is expired is the same as the previous article. The interface is called to obtain the generation time in the database and compare it with the current time. If it is greater than the set valid time, an exception is thrown, prompting that the verification code has expired, and please contact the administrator to resend the random key.
[0062] Furthermore, an embodiment of the present application discloses an electronic device, which may include: at least one processor, at least one memory, a power supply, a communication interface, an input / output interface, and a communication bus. The memory is used to store a computer program, which is loaded and executed by the processor to implement the relevant steps of the random key-based authentication method disclosed in any of the aforementioned embodiments. Furthermore, the electronic device in this embodiment may specifically be an electronic computer.
[0063] In this embodiment, the power supply is used to provide operating voltage for each hardware device on the electronic device; the communication interface can create a data transmission channel between the electronic device and the external device. The communication protocol it follows is any communication protocol that can be applied to the technical solution of this application and is not specifically limited here; the input and output interface is used to obtain external input data or output data to the outside world. The specific interface type can be selected according to specific application needs and is not specifically limited here.
[0064] In addition, the memory as a carrier for resource storage can be a read-only memory, random access memory, disk or CD, etc. The resources stored thereon can include an operating system, computer programs, etc., and the storage method can be temporary storage or permanent storage.
[0065] The operating system is used to manage and control the hardware devices and computer programs on the electronic device, and can be Windows Server, NetWare, Unix, Linux, etc. In addition to including a computer program capable of implementing the random key-based authentication method disclosed in any of the aforementioned embodiments and executed by the electronic device, the computer program may further include a computer program capable of implementing other specific tasks.
[0066] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when executed by a processor, the computer program implements the aforementioned random key-based authentication method. The specific steps of this method can be referred to the corresponding contents disclosed in the aforementioned embodiments and will not be repeated here.
[0067] The present invention provides an authentication method, device, equipment, and storage medium for identifying a user based on a random key. The method comprises: triggering a form sending event, obtaining a unique identifier for the current row, generating a random key using a random number algorithm, and sending the form; binding the unique identifier to the random key and setting a status value for the random key; adding the random key and a verification hyperlink to the email content in the body of an email template, and calling an email sending interface to send the email to a target website; logging into the target website, entering a random key, and determining whether the user is an authorized user; receiving the random key, and determining the status of a data verification code bound to the verification hyperlink. The present invention implements user and key binding by building a simple service internally, and implements verification functions through simple addition, deletion, modification, and querying, resulting in relatively low cost and high security.
[0068] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from the other embodiments. Reference can be made to the descriptions of the identical or similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and the relevant parts can be referred to the descriptions of the methods.
[0069] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0070] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0071] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.
[0072] The present invention provides a random key-based authentication method, apparatus, device, and storage medium. There are numerous methods and approaches for implementing this technical solution. The foregoing description is merely a preferred embodiment of the present invention. It should be noted that those skilled in the art may make various improvements and modifications without departing from the principles of the present invention, and such improvements and modifications are also within the scope of protection of the present invention. Any components not specified in this embodiment may be implemented using existing technologies.
Claims
1. A random key-based authentication method, characterized in that: include: Trigger the form sending event, obtain the unique identifier of the current row, use the random number algorithm to generate a random key, and send the form; Bind the unique identifier to the random key and set a status value for the random key; the status value is a Boolean value indicating whether the key has been verified, represented by checkResult, with a default value of false, i.e., unverified. When the key is entered by the user and the verification interface is called, if it is consistent with the key bound to the current data, the value is changed to true, indicating that the verification is successful; otherwise, it remains false. When the user logs in again to verify the key within the validity period, the status value is matched. If the value is true, the user is prompted that the key has been verified, and the user is prompted to proceed to the next step according to business needs, or prompted that the key has been verified and cannot be used further; if the value is false, subsequent verification is continued; Add the random key and verification hyperlink to the email content in the body of the email template, and call the email sending interface to send the email to the target website; The target website is a link to a website for background registration or verification of a random key; Log in to the target website, enter a random key, and determine whether the user is an authorized user; Receiving the random key, and determining the status of the data verification code bound to the verification hyperlink; The method of generating a random key by using a random number algorithm includes: inputting two parameters into a random algorithm function, namely a first parameter and a second parameter, wherein the first parameter is a type of the generated random number and the second parameter is a length of the generated random number; The verification hyperlink is hidden and displayed as a button hyperlink, and the unique identifier is encrypted and spliced into the verification hyperlink; The determining whether the user is an authorized user includes: if the user cannot provide a random key of a preset length, determining that the user is an unauthorized user; The receiving of the random key and determining the state of the data verification code bound to the verification hyperlink include: if the verification code state is inactive, determining whether the random key corresponding to the unique identifier is consistent with that in the database according to a unique identifier matching interface call; if the verification code state is active, prompting the user; Set the validity period of the random key. When generating the random key, record the current time and save it in the database, and bind it to the unique identifier. The receiving of the random key and the determination of the status of the data verification code bound to the verification hyperlink include: calling an interface to obtain the generation time in the database and comparing it with the current time; if the existence time of the data verification code bound to the hyperlink is greater than the set validity time, an exception is thrown to indicate that the data verification code bound to the hyperlink has expired.
2. An authentication device based on a random key implemented by the method according to claim 1, characterized in that: include: The form sending module is used to trigger the form sending event, obtain the unique identifier of the current row, generate a random key using a random number algorithm, and send the form; A status value setting module, configured to bind the unique identifier to the random key and set a status value for the random key; An email sending module is used to add the random key and the verification hyperlink to the email content in the body of the email template, and call the email sending interface to send the email to the target website; A user login module is used to log in to the target website, input a random key, and determine whether the user is an authorized user; The verification code determination module is used to receive the random key and determine the status of the data verification code bound to the verification hyperlink.
3. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the random key-based authentication method according to claim 1.
4. A computer-readable storage medium, characterized in that Used to store a computer program, which implements the random key-based authentication method according to claim 1 when executed by a processor.
Citation Information
Patent Citations
Improvements in and relating to data communications
WO2012032300A1