Verification code generation method and device, electronic equipment, storage medium and program product
By generating and encrypting CAPTCHAs locally and storing only the target index, the security risks of centralized CAPTCHA generation on servers are resolved, achieving a balance between security and availability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NETEASE (HANGZHOU) NETWORK CO LTD
- Filing Date
- 2025-12-10
- Publication Date
- 2026-04-28
AI Technical Summary
In existing technologies, the centralized generation of verification codes by servers makes it easy for attackers to obtain verification codes and corresponding device information in bulk, posing a security risk.
The original verification code is generated and encrypted locally. Only the target index corresponding to the target random number used for encryption is stored. Attackers cannot directly decrypt and obtain the original verification code. Instead, they decrypt it using the target random number sent by the server.
It improves security, prevents attackers from obtaining the original CAPTCHA, and achieves a balance between security and usability.
Smart Images

Figure CN121940128A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and more specifically to verification code generation methods, devices, electronic devices, storage media, and program products. Background Technology
[0002] Remote control systems are widely used in scenarios such as remote work, equipment maintenance, and technical support. Before establishing a remote connection, a verification code (or connection code) is usually required as an identity verification mechanism to prevent unauthorized access. In related technologies, a common approach is to have a server centrally generate the verification codes, with the client only serving as the display end. While this model is convenient for management, it has security vulnerabilities. Once an attacker compromises the server, they can obtain verification codes and corresponding device information in bulk. Summary of the Invention
[0003] This invention provides a verification code generation method, apparatus, electronic device, storage medium, and program product to solve the problem that centralized generation of verification codes by servers makes it easy for attackers to obtain verification codes and corresponding device information in bulk.
[0004] In a first aspect, the present invention provides a verification code generation method, comprising: In response to the verification code generation command, generate the original verification code; Obtain the target random number from the random number table sent by the server, and obtain the target index of the target random number in the random number table; The original verification code is encrypted using the target random number to generate an encrypted verification code; Generate a target configuration file containing the encrypted verification code and the target index; the target configuration file is used to restore the original verification code when it is necessary to display the original verification code.
[0005] The verification code generation method provided in this embodiment can generate the original verification code locally through a verification code generation command. Simultaneously, during the encryption process, a random number table stored on the server is introduced, while the local machine does not store the random number table, but only the target index corresponding to the target random number used for encryption. During an attack, attackers cannot directly decrypt the local configuration file to obtain the corresponding original verification code, thus improving security. Furthermore, since the original verification code is not stored on the server, attackers cannot directly obtain the original verification code corresponding to each controlled terminal after attacking the server. The controlled terminal, however, can decrypt the original verification code using the encrypted verification code and target index in the target configuration file, along with the target random number issued by the server, and display the corresponding original verification code, achieving a balance between security and usability.
[0006] Secondly, the present invention provides a verification code generation device, comprising: The verification code generation module is used to generate the original verification code in response to the verification code generation command.
[0007] The random number acquisition module is used to obtain the target random number from the random number table sent by the server, and to obtain the target index of the target random number in the random number table.
[0008] The verification code encryption module is used to encrypt the original verification code based on the target random number, and generate an encrypted verification code.
[0009] The configuration file generation module generates a target configuration file containing the encrypted verification code and the target index. This target configuration file is used to reconstruct the original verification code when it needs to be displayed.
[0010] Thirdly, the present invention provides an electronic device, comprising: a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the computer instructions to perform the verification code generation method of the first aspect or any corresponding embodiment described above.
[0011] Fourthly, the present invention provides a computer-readable storage medium storing computer instructions for causing a computer to execute the verification code generation method of the first aspect or any corresponding embodiment thereof.
[0012] Fifthly, the present invention provides a computer program product, including computer instructions for causing a computer to execute the verification code generation method of the first aspect or any corresponding embodiment thereof. Attached Figure Description
[0013] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0014] Figure 1 This is a schematic diagram of an application scenario according to an embodiment of the present invention; Figure 2 This is a schematic diagram of the first type of verification code generation method according to an embodiment of the present invention; Figure 3 This is a schematic diagram of a second process for a verification code generation method according to an embodiment of the present invention; Figure 4 This is a flowchart illustrating the overall process of generating a verification code according to an embodiment of the present invention; Figure 5 This is a structural block diagram of a verification code generation device according to an embodiment of the present invention; Figure 6 This is a schematic diagram of the hardware structure of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0015] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0016] It is understood that before using the technical solutions disclosed in the various embodiments of the present invention, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in the present invention and their authorization should be obtained in accordance with relevant laws and regulations through appropriate means.
[0017] The terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.
[0018] As an optional application scenario of this invention, such as Figure 1 As shown, application 101 is installed in terminal device 110, and user 130 can interact with application 101 through terminal device 110 and / or access device of terminal device 110.
[0019] For example, application 101 can be any application that provides remote control services. For instance, application 101 could be a remote control, remote interaction, or other similar application. Figure 1 In the application scenario shown, if application 101 is active, the terminal device 110 can display the interface 102 of application 101. The interface 102 may include various pages that application 101 can provide, such as interactive pages, settings pages, verification code display pages, etc.
[0020] In some embodiments, terminal device 110 is communicatively connected to server 120 to provide services to application 101. Terminal device 110 may be a mobile terminal, fixed terminal, or portable terminal, etc., including but not limited to mobile phones, desktop computers, laptop computers, multimedia tablets, e-book devices, gaming devices, or any combination thereof, including accessories and peripherals of these devices or any combination thereof. In some embodiments, terminal device 110 may also support any type of interface, and server 120 may be various types of computing systems or servers capable of providing computing power, including but not limited to mainframes, edge computing nodes, computing devices in cloud environments, etc.
[0021] It should be noted that, Figure 1 This is merely an example of an application scenario and does not limit the scope of protection of this invention.
[0022] The embodiments of the present invention will now be described with reference to the accompanying drawings. It should be understood that the pages shown in the drawings are merely examples, and various page designs are possible in practice. The various graphic elements on the page may have different arrangements and different visual representations; one or more elements may be omitted or replaced, and one or more other elements may also be present, without any limitation in the embodiments of the present invention. Furthermore, the embodiments described below primarily pertain to terminal device 110. It should be understood that the actions described relative to terminal device 110 can be performed by application 101 on terminal device 110, or can be performed by application 101 in conjunction with its server (e.g., server 120).
[0023] Remote control systems are widely used in scenarios such as remote work, equipment maintenance, and technical support. In related technologies, a common approach is for the server to generate verification codes, with the client only acting as a display end. However, once an attacker compromises the server, they can obtain verification codes and corresponding device information in bulk. Alternatively, there are methods for generating verification codes locally; however, these methods use overly simple encryption, allowing attackers to easily obtain the corresponding verification codes after compromising the client's terminal device.
[0024] This invention provides a verification code generation method. By generating and encrypting the original verification code locally, and storing only the target index corresponding to the target random number used for encryption, attackers cannot directly decrypt the local configuration file to obtain the corresponding original verification code during the attack process, thereby improving security.
[0025] According to an embodiment of the present invention, a verification code generation method embodiment is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0026] This embodiment provides a verification code generation method, which can be used in the aforementioned terminal devices, such as desktop computers, laptops, mobile phones, tablets, etc. Figure 2 This is a flowchart of a verification code generation method according to an embodiment of the present invention, such as... Figure 2 As shown, the process includes the following steps: Step S201: In response to the verification code generation instruction, generate the original verification code.
[0027] When establishing a remote connection, especially a remote control connection, a verification code is usually required as an authentication mechanism. For example, when the controlling end needs to control the controlled end via a remote connection, it can verify its identity by entering the verification code corresponding to the controlled end. When the controlled end needs to display the verification code, step S201 needs to be executed. For example, when the controlled end first opens the application corresponding to the remote control connection, there is no original verification code at this time, and an original verification code needs to be generated so that the controlling end can connect to the controlled end through the verification code. Typically, the original verification code can include letters, numbers, symbols, etc., and the length of the original verification code can be a default length, such as consisting of 8 letters, numbers, symbols, etc., or it can be a user-defined length. After receiving the verification code generation instruction, an original verification code can be generated.
[0028] Step S202: Obtain the target random number from the random number table sent by the server, and obtain the target index of the target random number in the random number table.
[0029] During the encryption process, if the original verification code is directly encrypted locally, the local machine needs to obtain and store the key, which may result in low security. In this case, a target random number from a random number table sent by the server can be introduced. The server can save the random number table, and when the controlled end needs to generate a verification code, it can send a request to the server to obtain a random number. At this time, the server can send the target random number to the controlled end. For example, the server can also send a target index corresponding to the target random number at the same time.
[0030] The target random number is used for the encryption process. In the random number table, each random number corresponds to an index, and the target random number corresponds to the target index. For example, the controlled terminal can randomly select a target index and send a request to obtain a random number containing the target index to the server. The server then returns the corresponding target random number to the controlled terminal based on the target index. In this embodiment, an entropy table can be used as the random number table, with each entropy value in the entropy table serving as a random number. An entropy value can be randomly selected as the target random number, and the entropy index corresponding to the target entropy value (i.e., the target random number) is simultaneously sent to the controlled terminal.
[0031] Step S203: Encrypt the original verification code according to the target random number to generate an encrypted verification code.
[0032] As mentioned earlier, encrypting the original CAPTCHA locally requires obtaining and storing the key, which may lead to insufficient security. Therefore, a target random number can be incorporated into the encryption process. For example, Windows' DPAPI (Data Protection Application Programming Interface) can be used to encrypt the original CAPTCHA using the target random number, and then a Base64 encoded encrypted CAPTCHA can be generated. The encrypted CAPTCHA is the final, encrypted version. After encryption, if an attacker attacks the compromised device and obtains the encrypted CAPTCHA, they cannot obtain the target random number itself, but only the target index. Therefore, they cannot directly decrypt the encrypted CAPTCHA, ensuring security.
[0033] Step S204: Generate a target configuration file containing the encrypted verification code and the target index. The target configuration file is used to restore the original verification code when it is necessary to display the original verification code.
[0034] After generating the encrypted verification code, the encrypted verification code and the target index are combined to form a target configuration file, which is stored on the local path of the controlled device. Since the target configuration file only contains the encrypted verification code and the target index, attackers, after obtaining the target configuration file from the controlled device, cannot directly decrypt the encrypted verification code using the target index, thus increasing the security of the encrypted verification code. As the controlled device, when it needs to display the original verification code, it can decrypt the target configuration file. For example, when launching the corresponding remote control application for the second time, it needs to display the original verification code to inform the controlling end that it has remote control rights over the controlled device. In this case, it can decrypt the target configuration file to obtain and display the decrypted original verification code.
[0035] The verification code generation method provided in this embodiment can generate the original verification code locally through a verification code generation command. Simultaneously, during the encryption process, a random number table stored on the server is introduced, while the local machine does not store the random number table, but only the target index corresponding to the target random number used for encryption. During an attack, attackers cannot directly decrypt the local configuration file to obtain the corresponding original verification code, thus improving security. Furthermore, since the original verification code is not stored on the server, attackers cannot directly obtain the original verification code corresponding to each controlled terminal after attacking the server. The controlled terminal, however, can decrypt the original verification code using the encrypted verification code and target index in the target configuration file, along with the target random number issued by the server, and display the corresponding original verification code, achieving a balance between security and usability.
[0036] This embodiment provides a verification code generation method, which can be used in the aforementioned terminal devices, such as desktop computers, laptops, mobile phones, tablets, etc. Figure 3 This is a flowchart of a verification code generation method according to an embodiment of the present invention, such as... Figure 3 As shown, the process includes the following steps: Step S301: In response to the verification code generation instruction, generate the original verification code.
[0037] Please see details Figure 2 Step S201 of the illustrated embodiment will not be described again here.
[0038] In some alternative implementations, step S301, “generating the original verification code,” includes step a1 or step a2.
[0039] Step a1: Select a fixed length of random characters to generate the original verification code.
[0040] Step a2: Generate the original verification code based on the characters entered by the user.
[0041] During the generation of the initial verification code, random characters can be used. For example, a fixed length of random characters can be selected from a predefined character set (containing uppercase letters, lowercase letters, and numbers) to generate the initial verification code. The fixed length can be a preset length, i.e., the number of characters, such as 8 or 10 characters. For instance, a randomly generated initial verification code could be SAd7fasKj2 (10 characters long). Furthermore, in some scenarios, such as when a user needs to remotely control a workstation machine in the workplace, the user can set an easy-to-remember initial verification code. For example, the user's input could be "MyComPuter," and the corresponding initial verification code "MyComPuter" can be generated based on the user's input.
[0042] Step S302: Obtain the target random number from the random number table sent by the server, and obtain the target index of the target random number in the random number table.
[0043] Please see details Figure 2 Step S202 of the illustrated embodiment will not be described again here.
[0044] Step S303: Encrypt the original verification code according to the target random number to generate an encrypted verification code.
[0045] Please see details Figure 2 Step S203 of the illustrated embodiment will not be described again here.
[0046] Step S304: Generate a target configuration file containing the encrypted verification code and the target index. The target configuration file is used to restore the original verification code when it is necessary to display the original verification code.
[0047] Please see details Figure 2 Step S204 of the illustrated embodiment will not be described again here.
[0048] Furthermore, the method also includes steps S305 and S306.
[0049] Step S305: In response to the request to display the verification code, if the target configuration file exists locally, the encrypted verification code in the target configuration file is decrypted to obtain the original verification code.
[0050] When a verification code needs to be displayed, i.e., when there is a request to display a verification code, such as after generating the original verification code and encrypting and storing the target configuration file corresponding to the encrypted verification code, and then needing to display the original verification code for input on the control terminal, the existence of the configuration file can be checked. If the target configuration file was generated and stored in step S304, then the target configuration file exists locally. The encrypted verification code corresponding to the encrypted verification code in the target configuration file can be decrypted to obtain the original verification code corresponding to the encrypted verification code, i.e., the original verification code corresponding to the target configuration file when it was generated.
[0051] It is understandable that the existence of a target configuration file can be checked before step S301. For example, when the client application starts, a verification code needs to be displayed. At this time, a display request can be automatically generated, and the existence of a target configuration file can be checked first. If the target configuration file does not exist, step S301 is executed; if the target configuration file exists, step S305 is executed.
[0052] In some optional implementations, step S305, "decrypting the encrypted verification code in the target configuration file to obtain the original verification code", includes steps S3051 and S3052.
[0053] Step S3051: Obtain the target random number sent by the server corresponding to the target index according to the target index in the target configuration file.
[0054] Step S3052: Decrypt the encrypted verification code according to the target random number to obtain the corresponding original verification code.
[0055] As mentioned earlier, the target configuration file contains not only the encrypted verification code but also the target index corresponding to the target random number used for encryption. During decryption, if only the encrypted verification code is available without the corresponding target random number, decryption will fail. In this case, a request to obtain the target random number can be sent to the server, and this request can include the target index. After receiving the request, the server can query the random number table based on the target index to obtain the target random number corresponding to the target index, and then send the target random number to the controlled terminal. After obtaining the target random number corresponding to the target index sent by the server, the encrypted verification code can be decrypted based on the target random number. That is, the encrypted verification code can be decrypted using the algorithm used during encryption (e.g., decryption based on DPAPI) using the target random number to obtain the original verification code corresponding to the encrypted verification code.
[0056] In some optional implementations, the original verification code corresponds to the first user identifier that issued the verification code generation instruction, and the target configuration file also includes the first user identifier. Step S305, "decrypting the encrypted verification code in the target configuration file to obtain the original verification code", includes steps b1 and b2.
[0057] Step b1: Check whether the first user identifier in the target configuration file corresponds to the second user identifier in the display request.
[0058] Step b2: If the first user identifier corresponds to the second user identifier, decrypt the encrypted verification code in the target configuration file to obtain the original verification code.
[0059] On the same controlled terminal, multiple users can generate original verification codes corresponding to their own users. For example, user A can generate original verification code 'a', and user B can generate original verification code 'b'. That is, the generated original verification codes correspond to the user identifiers used in the generation commands. For each user, a corresponding configuration file can be generated. If the target configuration file contains the original verification code generated by the first user, then that original verification code corresponds to the first user identifier. Furthermore, during the process of generating the target configuration file after encryption, the first user identifier corresponding to the original verification code also needs to be stored simultaneously.
[0060] During the decryption process, it is also necessary to decrypt the encrypted verification code corresponding to the current user (i.e., the second user in the display request) based on the current user identifier (i.e., the second user identifier). At this time, it is possible to check whether the first user identifier stored in each target configuration file is consistent with the current second user identifier (i.e., whether the first user identifier corresponds to the second user identifier). If the first user identifier and the second user identifier are consistent, it means that the second user corresponding to the current display request has previously generated the original verification code. At this time, the encrypted verification code in the target configuration file corresponding to the second user identifier can be decrypted to obtain the original verification code corresponding to the second user identifier, for example, by executing steps S3051 and S3052.
[0061] By storing the first user identifier in the target configuration file, different users can be associated with different encrypted verification codes. During the decryption process, the original verification code corresponding to the current user is displayed to ensure security.
[0062] In some optional implementations, the random number table corresponds to a first version identifier, the target configuration file also includes a first version identifier, and step S305 "decrypts the encrypted verification code in the target configuration file to obtain the original verification code" includes steps c1 and c2.
[0063] Step c1: If the target configuration file exists locally, obtain the second version identifier of the current random number table from the server.
[0064] Step c2: If the second version identifier is the same as the first version identifier, decrypt the encrypted verification code in the target configuration file to obtain the original verification code.
[0065] In some cases, the random number table stored on the server can have multiple versions, each with a corresponding version identifier. During encryption, the server can send the version identifier along with the target random number to the controlled terminal; in this case, the version identifier becomes the first version identifier. During the generation of the target configuration file after encryption based on the target random number, the first version identifier can be stored in the target configuration file.
[0066] During the process of decrypting the target configuration file to obtain the original verification code, the first version identifier in the target configuration file can be compared with the second version identifier corresponding to the random number table currently stored on the server. Specifically, the second version identifier corresponding to the server's current random number table is received, and the local system checks whether the second version identifier matches the first version identifier. If the second version identifier matches the first version identifier, it means that the random number table used to generate the verification code locally is consistent with the version of the random number table currently stored on the server. This means that the encrypted verification code in the target configuration file can be decrypted to obtain the corresponding original verification code. For example, steps S3051 and S3052 can be executed.
[0067] Understandably, the target configuration file may store both the first user identifier and the first version identifier. In this case, the first user identifier must match the second user identifier, and the first version identifier must match the second version identifier for decryption to proceed.
[0068] In some optional implementations, step S302, "obtaining the target random number from the random number table sent by the server and obtaining the target index of the target random number in the random number table", includes steps d1 and d2, or steps d3 and d4.
[0069] Step d1: Send a first retrieval request to the server to obtain the random number table, and retrieve the random number table containing multiple random numbers sent by the server. The version identifier of the random number table is the first version identifier.
[0070] Step d2: Select a target random number from the random number table and determine the target index of the target random number in the random number table.
[0071] In the process of obtaining the target random number from the random number table sent by the server, and obtaining the target index of the target random number in the random number table, the controlled terminal can first initiate a first retrieval request to the server. This first retrieval request is used to cause the server to issue a random number table with a first version identifier. After obtaining the random number table, a target random number can be randomly selected from the random number table, and the target index corresponding to the target random number in the random number table is recorded. The target random number is used to encrypt the original verification code, while the target index is used to obtain the corresponding target random number from the server when decrypting the encrypted verification code. To ensure security, i.e., the random number table is not stored locally, the locally stored random number table and the target random number can be deleted, and only the target index corresponding to the target random number is recorded.
[0072] Step d3: Initiate a second retrieval request to the server to obtain the index of the random number table, and obtain the first version identifier of the random number table sent by the server and the index of each random number in the random number table.
[0073] Step d4: Send the target index selected from each index to the server, and obtain the target random number corresponding to the target index sent by the server.
[0074] During the process of obtaining the target random number from the random number table sent by the server, and obtaining the target index of the target random number in the random number table, the controlled terminal can also initiate a second retrieval request to the server. This second retrieval request is used to cause the server to send partial information from the random number table with the first version identifier. This partial information does not contain the original random numbers, only the indices of each random number. At this point, an index can be randomly selected from the various random number indices as the target index, and sent to the server. The server determines the target random number corresponding to the target index based on the random number table and sends the target random number to the controlled terminal for the encryption process of the original verification code. After the encryption process is completed, the controlled terminal can delete the target random number, retaining only the target index and storing it in the target configuration file. Since the random number table and target random number are not stored locally, only the target index is stored, thus ensuring security.
[0075] In some alternative implementations, the method further includes step e1.
[0076] Step e1: If the target configuration file cannot be decrypted, generate a new original verification code to regenerate the new configuration file.
[0077] If the target configuration file cannot be decrypted, for example, if the target configuration file is corrupted, or if a certain field is missing and cannot be decrypted, or if the field length does not meet the rules, it can be determined that the target configuration file is corrupted. At this time, a new original verification code can be generated, that is, step S301 is re-executed.
[0078] In some cases, the target configuration file may fail to decrypt. For example, if the target configuration file includes a first version identifier, and this first version identifier differs from the second version identifier in the random number table stored on the server, the target random number cannot be determined using the target index. In this situation, a new original verification code can be generated, and step S301 can be re-executed. In practical applications, the server can periodically update the version of the random number table stored on the server, as well as the corresponding random number table version identifier (i.e., the second version identifier). After the server updates the random number table version identifier, the first version identifier and the second version identifier stored in the target configuration file on the controlled end will be inconsistent, meaning the target configuration file cannot be decrypted. A new original verification code can be generated, and the server will encrypt the target random number determined from the new random number table version and store the new first version identifier to achieve dynamic updates of encryption security.
[0079] In addition, in some cases, the target configuration file may not be decryptable. For example, if the target configuration file includes a first user identifier, the current user identifier (i.e., the second user identifier) may not be consistent with the first user identifier in the target configuration file. In other words, the target configuration file cannot be determined by the current user identifier. In this case, an original verification code corresponding to the current user identifier can be generated for the current user, i.e., step S301 is re-executed.
[0080] Step S306: Display the original verification code obtained through decryption.
[0081] After decrypting the encrypted verification code, the original verification code obtained through decryption is displayed in the application. Users can then remotely control the controlled device by inputting the original verification code on the control terminal.
[0082] In some alternative implementations, the target configuration file has a corresponding timestamp, and the method further includes step f1.
[0083] Step f1: If the time difference between the current time marker and the time marker corresponding to the target configuration file is greater than a preset time threshold, delete the target configuration file.
[0084] During the generation of the target configuration file, a timestamp corresponding to the target configuration file can be stored simultaneously. For example, the generation time of the target configuration file can be used as the timestamp, or the generation time of the original verification code or encrypted verification code can be used as the timestamp; specifically, this timestamp can be a timestamp. If the application detects that the time difference between the current timestamp corresponding to the current time and the timestamp corresponding to the target configuration file is greater than a preset time threshold, it can be determined that the target configuration file has expired. At this time, the target configuration file can be deleted, a new verification code generation instruction can be generated, and the original verification code can be regenerated, i.e., step S301 can be re-executed. The preset time threshold can be a default time threshold, such as 12 hours, or it can be determined according to a user-defined value. By using the relationship between the time threshold, the current timestamp, and the timestamp corresponding to the target configuration file, the effect of updating (i.e., regenerating) the original verification code and encrypting it at certain intervals can be achieved to ensure security.
[0085] In some alternative implementations, the method further includes step g1 or step g2.
[0086] Step g1: If the configuration file does not exist locally, generate the verification code generation command.
[0087] If no configuration file exists locally, meaning no original verification code has been generated yet, a verification code generation command can be generated and step S301 can be executed.
[0088] Step g2: In response to the user-initiated verification code generation operation, a verification code generation instruction is generated.
[0089] In some cases, users may want to refresh the current original verification code, or users may manually enter an original verification code. In this case, the controlled terminal may respond to the user's original verification code refresh operation or the user's operation of manually entering an original verification code, that is, generate a new verification code generation instruction for this operation and execute step S301.
[0090] Figure 4 This is a complete flowchart according to this embodiment. Upon receiving a request to display a verification code, the system first checks if a configuration file exists locally. If a configuration file exists, it checks if the file has expired. If no configuration file exists, a verification code generation instruction is generated to generate the original verification code. A verification code generation instruction is also generated if the user chooses to manually refresh the verification code. After generating the original verification code, it is encrypted using a target random number sent by the server, and the encrypted verification code is stored in the target configuration file. The target configuration file may include a version identifier corresponding to the random table (i.e., the first version identifier), a target index corresponding to the target random number, a user identifier that generated the verification code generation instruction (i.e., the first user identifier), and a timestamp of the target configuration file. After storing the target configuration file, if a request to display a verification code is received, it can be determined whether the target configuration file has expired. This is done by checking if the time difference between the timestamp of the target configuration file and the current timestamp is greater than a preset time threshold. If it is greater than the preset time threshold, the target configuration file has expired, and a new verification code generation instruction is generated. If it is less than the preset time threshold, the target configuration file has not expired and can be decrypted. During the decryption process, a target random number needs to be retrieved from the server based on the stored target index for decryption, and the original verification code is then obtained and displayed. In some cases, the target configuration file cannot be decrypted, such as when the file is corrupted, or when the first user identifier does not match the current user identifier (i.e., the second user identifier), or when the first version identifier does not match the version identifier corresponding to the random number table stored on the server (i.e., the second version identifier). In these cases, the target configuration file cannot be decrypted. In such situations, a new verification code generation instruction can be generated to regenerate the original verification code.
[0091] The verification code generation method provided in this embodiment can generate the original verification code locally through verification code generation instructions. During the encryption process, a random number table stored on the server is introduced, while the local machine does not store the random number table itself, but only the target index corresponding to the target random number used for encryption. Attackers cannot directly decrypt the local configuration file to obtain the corresponding original verification code during an attack, thus improving security. A random number table version identifier comparison is added. If the random number table identifier stored locally is inconsistent with the random number table identifier stored on the server, the original verification code is regenerated. The random number table version can be updated periodically on the server to achieve long-term security maintenance and avoid compatibility issues caused by the expiration of old random number versions. By binding the encryption method to the user identifier, the verification code can be securely and persistently stored locally and correctly decrypted and displayed after the application restarts. Furthermore, since the original verification code is not stored on the server, attackers cannot directly obtain the original verification codes corresponding to each controlled terminal after attacking the server. However, the controlled terminal can decrypt the encrypted verification code and target index in the target configuration file using the target random number issued by the server and display the corresponding original verification code, achieving a balance between security and usability.
[0092] This embodiment also provides a verification code generation device, which is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0093] This embodiment provides a verification code generation device, such as... Figure 5 As shown, it includes: The verification code generation module 501 is used to generate the original verification code in response to the verification code generation instruction.
[0094] The random number acquisition module 502 is used to acquire the target random number from the random number table sent by the server, and to acquire the target index of the target random number in the random number table.
[0095] The verification code encryption module 503 is used to encrypt the original verification code based on the target random number to generate an encrypted verification code.
[0096] The configuration file generation module 504 is used to generate a target configuration file containing an encrypted verification code and a target index. The target configuration file is used to reconstruct the original verification code when it is necessary to display the original verification code.
[0097] In some alternative embodiments, the device further includes: The verification code decryption module is used to respond to the request to display the verification code. If the target configuration file exists locally, it decrypts the encrypted verification code in the target configuration file to obtain the original verification code.
[0098] The verification code display module is used to display the original verification code obtained through decryption.
[0099] In some optional implementations, the CAPTCHA decryption module includes: The random number acquisition submodule is used to obtain the target random number sent by the server corresponding to the target index based on the target index in the target configuration file.
[0100] The first verification code decryption submodule is used to decrypt the encrypted verification code based on the target random number to obtain the corresponding original verification code.
[0101] In some optional implementations, the original verification code corresponds to the first user identifier that issued the verification code generation instruction, and the target configuration file also includes the first user identifier. The verification code decryption module includes: The user identifier checking submodule is used to check whether the first user identifier in the target configuration file corresponds to the second user identifier in the display request.
[0102] The second verification code decryption submodule is used to decrypt the encrypted verification code in the target configuration file to obtain the original verification code when the first user identifier and the second user identifier correspond.
[0103] In some optional implementations, the random number table corresponds to a first version identifier, and the target configuration file also includes a first version identifier. The CAPTCHA decryption module includes: The version identifier check submodule is used to obtain the second version identifier of the current random number table from the server, provided that the target configuration file exists locally.
[0104] The third verification code decryption submodule is used to decrypt the encrypted verification code in the target configuration file to obtain the original verification code when the second version identifier is the same as the first version identifier.
[0105] In some alternative implementations, the random number generation module 502 includes: The first retrieval request submodule is used to initiate a first retrieval request to the server to retrieve a random number table containing multiple random numbers. The version identifier of the random number table is the first version identifier.
[0106] The first random number determination submodule is used to select a target random number from the random number table and determine the target index of the target random number in the random number table.
[0107] or, The second retrieval request submodule is used to send a second retrieval request to the server to retrieve the index of the random number table, and to retrieve the first version identifier of the random number table sent by the server and the index of each random number in the random number table.
[0108] The second random number determination submodule is used to send the target index selected from various indexes to the server and obtain the target random number sent by the server corresponding to the target index.
[0109] In some alternative embodiments, the device further includes: The regeneration module is used to generate a new original verification code in case the target configuration file cannot be decrypted, so as to regenerate a new configuration file.
[0110] In some optional implementations, the target configuration file has a corresponding timestamp, and the device further includes: The timeout deletion module is used to delete the target configuration file if the time difference between the current time marker and the time marker corresponding to the target configuration file is greater than a preset time threshold.
[0111] In some alternative embodiments, the device further includes: The first generation module is used to generate verification code generation instructions when no configuration file exists locally.
[0112] The second generation module is used to generate a verification code generation instruction in response to a user-initiated verification code generation operation.
[0113] The verification code generation device provided in this embodiment of the invention can execute the verification code generation method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the method. Further functional descriptions of the various modules and units are the same as in the corresponding embodiments described above, and will not be repeated here.
[0114] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention.
[0115] The following is a detailed reference. Figure 6This diagram illustrates a suitable structural design for implementing an electronic device according to embodiments of the present invention. The electronic device may include a processor (e.g., a central processing unit, graphics processor, etc.) 601, which can perform various appropriate actions and processes based on a program stored in read-only memory (ROM) 602 or a program loaded from memory 608 into random access memory (RAM) 603. RAM 603 also stores various programs and data required for the operation of the electronic device. The processor 601, ROM 602, and RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0116] Typically, the following devices can be connected to I / O interface 605: input devices 606 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 607 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; memory devices 608 including, for example, magnetic tapes, hard disks, etc.; and communication devices 609. Communication device 609 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 6 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown, and more or fewer devices may be implemented or have instead.
[0117] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 609, or installed from a memory 608, or installed from a ROM 602. When the computer program is executed by the processor 601, it performs the functions defined in the verification code generation method of the embodiments of the present invention.
[0118] Figure 6 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments of the present invention.
[0119] This invention also provides a computer-readable storage medium. The methods described above according to embodiments of the invention can be implemented in hardware or firmware, or implemented as computer code that can be recorded on a storage medium, or implemented as computer code downloaded via a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and then stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code. When the software or computer code is accessed and executed by the computer, processor, or hardware, the verification code generation method shown in the above embodiments is implemented.
[0120] A portion of this invention can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to the invention through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions, or the computer compiling the instructions and then executing the corresponding compiled program, or the computer reading and executing the instructions, or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.
[0121] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined by the appended claims.
Claims
1. A method for generating verification codes, characterized in that, The method includes: In response to the verification code generation command, generate the original verification code; Obtain the target random number from the random number table sent by the server, and obtain the target index of the target random number in the random number table; The original verification code is encrypted using the target random number to generate an encrypted verification code; Generate a target configuration file containing the encrypted verification code and the target index; the target configuration file is used to restore the original verification code when it is necessary to display the original verification code.
2. The method according to claim 1, characterized in that, The method further includes: In response to a request to display a verification code, if the target configuration file exists locally, the encrypted verification code in the target configuration file is decrypted to obtain the original verification code. Display the original verification code obtained through decryption.
3. The method according to claim 2, characterized in that, The process of decrypting the encrypted verification code in the target configuration file to obtain the original verification code includes: Based on the target index in the target configuration file, obtain the target random number sent by the server that corresponds to the target index; The encrypted verification code is decrypted based on the target random number to obtain the corresponding original verification code.
4. The method according to claim 2, characterized in that, The original verification code corresponds to the first user identifier that issued the verification code generation instruction, and the target configuration file further includes the first user identifier; the step of decrypting the encrypted verification code in the target configuration file to obtain the original verification code includes: Check whether the first user identifier in the target configuration file corresponds to the second user identifier in the display request; If the first user identifier corresponds to the second user identifier, the encrypted verification code in the target configuration file is decrypted to obtain the original verification code.
5. The method according to claim 2, characterized in that, The random number table corresponds to a first version identifier, and the target configuration file also includes the first version identifier; the step of decrypting the encrypted verification code in the target configuration file to obtain the original verification code includes: If the target configuration file exists locally, obtain the second version identifier of the current random number table from the server; If the second version identifier is the same as the first version identifier, the encrypted verification code in the target configuration file is decrypted to obtain the original verification code.
6. The method according to claim 5, characterized in that, The step of obtaining the target random number from the random number table sent by the server and obtaining the target index of the target random number in the random number table includes: A first retrieval request is sent to the server to obtain a random number table, and the random number table containing multiple random numbers sent by the server is obtained; the version identifier of the random number table is a first version identifier; Select a target random number from the random number table, and determine the target index of the target random number in the random number table; or, A second retrieval request is sent to the server to obtain the index of the random number table, and the first version identifier of the random number table sent by the server and the index of each random number in the random number table are obtained. Send the target index selected from various indexes to the server, and obtain the target random number corresponding to the target index sent by the server.
7. The method according to any one of claims 2 to 6, characterized in that, The method further includes: If the target configuration file cannot be decrypted, a new original verification code is generated to regenerate the new configuration file.
8. The method according to claim 1, characterized in that, The target configuration file has a corresponding time identifier, and the method further includes: If the time difference between the current time marker and the time marker corresponding to the target configuration file is greater than a preset time threshold, the target configuration file is deleted.
9. The method according to claim 1 or 2, characterized in that, The method further includes: If the configuration file does not exist locally, the verification code generation instruction is generated. or, In response to a user-initiated verification code generation operation, the verification code generation instruction is generated.
10. A verification code generation device, characterized in that, The device includes: The verification code generation module is used to generate the original verification code in response to the verification code generation command; The random number acquisition module is used to acquire a target random number from a random number table sent by the server, and to acquire the target index of the target random number in the random number table; The verification code encryption module is used to encrypt the original verification code according to the target random number to generate an encrypted verification code; The configuration file generation module is used to generate a target configuration file containing the encrypted verification code and the target index; the target configuration file is used to restore the original verification code when it is necessary to display the original verification code.
11. An electronic device, characterized in that, include: A memory and a processor are communicatively connected, the memory stores computer instructions, and the processor executes the computer instructions to perform the verification code generation method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing the computer to perform the verification code generation method according to any one of claims 1 to 9.
13. A computer program product, characterized in that, It includes computer instructions for causing a computer to perform the verification code generation method according to any one of claims 1 to 9.