A method and apparatus for generating and verifying image CAPTCHAs

By generating and verifying image CAPTCHAs in the client browser using WebAssembly and the browser sandbox environment, and combining this with digital signatures using public-key cryptography algorithms, the problems of high server load and attack risk are solved, achieving efficient CAPTCHA processing and enhanced security.

CN116305054BActive Publication Date: 2026-11-17湖北省楚天云有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310172992.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2022-12-27
Filing Date
2023-02-27
Publication Date
2026-11-17
Estimated Expiration
2043-02-27

AI Technical Summary

Technical Problem

In existing technologies, the generation and verification of image verification codes are completed by the server, which increases server load and attack risks, and is also inefficient.

Method used

The image CAPTCHA is generated and verified in the client browser using WebAssembly (WASM). The CAPTCHA is created, cached, displayed and verified using the browser sandbox environment, and digital signature verification is performed using public key cryptography algorithms.

Benefits of technology

It reduces client-server interaction, improves the efficiency of CAPTCHA generation and verification, enhances user satisfaction, and reduces server computational overhead and security risks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116305054B_ABST
    Figure CN116305054B_ABST
Patent Text Reader

Abstract

This invention discloses a method and apparatus for generating and verifying image CAPTCHAs. The method includes: a client creating a session for submitting a request and caching the session in the browser sandbox memory; obtaining a CAPTCHA request and generating a baseline CAPTCHA; converting the baseline CAPTCHA into an image CAPTCHA for display; obtaining the input user CAPTCHA and verifying it in the browser sandbox, and outputting the verification result. In this invention, the image CAPTCHA generation and verification processes are completed within the client browser, improving the efficiency of image CAPTCHA generation and verification, and enhancing user satisfaction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of information security technology, specifically to a method and apparatus for generating and verifying image verification codes. Background Technology

[0002] Current technology typically involves a server generating a string of random numbers or symbols, then using graphics rendering to convert the string into a visible image. The image file stream is returned to the client, which displays the image to the user through a browser. After completing the form on the page, the user must enter a verification code based on this image before submitting. Once submitted to the server, the server first verifies the verification code; if they don't match, an error message is returned to the client informing the user. Only after successful verification does the subsequent execution process proceed. Therefore, having the server handle the generation and verification of the verification code image increases server load and the risk of attacks. Summary of the Invention

[0003] In view of this, it is necessary to propose a method and device for generating and verifying image CAPTCHAs.

[0004] This invention discloses a method for generating and verifying image CAPTCHAs, comprising the following steps:

[0005] The client creates a session for submitting requests and caches the session in the browser's sandbox memory;

[0006] Obtain a verification code request and generate a baseline verification code;

[0007] Convert the standard CAPTCHA into an image CAPTCHA for display.

[0008] Retrieve the input user verification code and perform verification in the browser sandbox, then output the verification result.

[0009] Furthermore, the client creates a session for submitting requests and caches the session in the browser's sandbox memory, including:

[0010] The client calls the CreateSession interface of WASM in the sandbox via JavaScript to create and return a session, which is then cached in the browser's sandbox memory.

[0011] Furthermore, the client receives a verification code request and generates a baseline verification code, including:

[0012] After the client obtains the verification code request, it calls the GenerateCaptcha interface in WASM via JavaScript, passing the session as a parameter.

[0013] Generate a baseline verification code and cache the correspondence between the session and the baseline verification code in the browser sandbox memory as key-value pairs, wherein the baseline verification code is in alphanumeric form.

[0014] Furthermore, the client converts the baseline CAPTCHA into an image CAPTCHA for display, and also includes:

[0015] Convert the standard CAPTCHA into an image CAPTCHA;

[0016] Return the Base64 value of the image verification code;

[0017] The src attribute of the preset img tag for the verification code is dynamically changed using JavaScript, and the browser renders the image verification code before displaying it to the user.

[0018] Furthermore, the client obtains the input user verification code and performs verification code validation within the browser sandbox, including:

[0019] The client calls the VerifyCaptcha interface in the WASM sandbox via JavaScript, passing in the session and user verification code as parameters;

[0020] The VerifyCaptcha interface determines the correctness of the mapping between the input user verification code and the session based on the cached baseline verification code and the session mapping. If it is incorrect, an error is returned.

[0021] Otherwise, generate the current timestamp value string, sign the current timestamp value string using the preset private key, and return the signed value.

[0022] Furthermore, the client uses an AJAX request to send the user-submitted data, the current timestamp string, and the signature value to the server.

[0023] On the other hand, the present invention also discloses an image verification code generation and verification device, including a client and a server, wherein the client includes a key pair generation unit, a session creation unit, a baseline verification code generation unit, a verification code display unit, a first verification unit, and a second verification unit.

[0024] A key pair generation unit is used to generate a key pair, wherein the private key is pre-set in the client browser sandbox and the public key is pre-set in the server;

[0025] The session creation unit is used to create a session for submitting a request and cache the session in the browser's sandbox memory;

[0026] The baseline verification code generation unit receives verification code requests and generates baseline verification codes.

[0027] The verification code display unit is used to convert the baseline verification code into an image verification code for display.

[0028] The first verification unit is used to obtain the input user verification code and verify the verification code in the browser sandbox.

[0029] The second verification unit sends the current timestamp value string and the signature value to the server, receives the server's verification result of the signature value based on the current timestamp value string and the preset public key, and outputs the verification result.

[0030] The server is used to receive the current timestamp value string and signature value sent by the second verification unit, and to verify the signature value according to the current timestamp value string and the preset public key, and send the verification result to the client.

[0031] Based on the above technical solution, the beneficial effects of the present invention compared with the prior art are as follows: In the embodiments of the present invention, the image verification code generation and verification process are completed in the client browser, which can avoid the interaction between the client and the server, improve the efficiency of verification code generation and verification, and enhance user satisfaction. Attached Figure Description

[0032] Figure 1 This is a flowchart of an image verification code generation and verification method in Embodiment 1;

[0033] Figure 2 This is a flowchart of an image verification code generation and verification method in Embodiment 2;

[0034] Figure 3 This is a detailed working interaction diagram of an image verification code generation and verification method in Embodiment 2;

[0035] Figure 4 This is a schematic diagram of a client structure in Embodiment 3;

[0036] Figure 5 This is a schematic diagram of another client structure in Embodiment 4. Detailed Implementation

[0037] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0038] Browser: A browser is an application used to retrieve, display, and deliver web information resources. Browsers are generally installed on electronic devices such as PCs and mobile phones, allowing users to log in and access various online applications.

[0039] WASM, short for WebAssembly, is a binary instruction set designed for a stack-based virtual machine. It's a technology that allows code to be written in languages ​​other than Java / JavaScript and run in a browser. WASM is characterized by high performance, low storage costs, and multi-language support, making it developer-friendly. Furthermore, because it runs in a browser sandbox environment, it also offers code and runtime security.

[0040] Image CAPTCHA: An image CAPTCHA is a string of random numbers or symbols generated using a specific random number generation algorithm, with some noise pixels added to create a verification image. Its main purpose is to prevent users from using tools to submit data in bulk, thus preventing brute-force attacks in scenarios such as logins and flash sales.

[0041] JavaScript: A dynamic scripting language that can run in a browser, embedding dynamic text in web pages, having the ability to respond to browser events, read and write HTML elements in web pages, and validate data in the browser before it is submitted to the server.

[0042] A session is a non-interrupted sequence of requests and responses between a user and a service. For each request from a user, the service can identify that the request originated from the same user. Session isolation can be used between users and services to maintain the same purpose across multiple requests. Typically, a session is initiated by the user and maintained by the service.

[0043] Sandbox: A security mechanism that provides an isolated environment for running programs. Sandboxes typically strictly control the resources that programs within them can access; for example, they can provide disk and memory space that is reclaimed after use. Within a sandbox, network access, access to the real system, and reading of input devices are usually prohibited or strictly limited. From this perspective, sandboxing is a type of virtualization. All changes made within a sandbox will not cause any damage to the operating system.

[0044] Key-value pairs: In computer science, key-value pairs are a fundamental data representation in computing systems and applications. In this data structure, all or part of the data model can be represented as a set of tuples.<key,value> For example, {Name:Zhang San, Gender:Male} is a collection with two key-value pairs, where each element is a key-value pair. Collections can be used to represent a specific object.

[0045] The img tag: In HTML, the img tag can be used to represent an image. When a browser parses an HTML page and encounters an img tag, it should render the image element pointed to by the img tag in the specified position on the browser page and display it to the user.

[0046] The src attribute: In HTML, the img tag can have a src attribute, which can be a URL address pointing to a network-reachable meta file. Alternatively, the base64 value of the meta file can be placed directly in the HTML element using the form data:base64.

[0047] Rendering: Rendering is one of the most important research topics in 3D computer graphics, and it is the process of imaging a model. In a browser, primitive rendering refers to the process by which the browser uses the computer's graphics capabilities to draw primitives onto a surface that is directly visible to the user.

[0048] Timestamp: A time value generated by a computer based on the current time. It can be represented as a numeric integer to indicate the number of seconds that have elapsed since January 1, 1970 (00:00:00 GMT) (or in milliseconds, microseconds, or nanoseconds). It can also be represented as a string of the current time, or even as a digitally signed time structure.

[0049] Public / Private Keys: In public-key cryptography, encryption and decryption use different keys. One key is made public and is called the public key, while the other is kept secret by the user and is called the user's private key. In encryption / decryption applications, the sender should encrypt the data using the recipient's public key and send it to the recipient. After sending the data, the recipient uses their own private key to decrypt it. In signature / verification applications, the sender should sign the data using their own private key and send it to the recipient. After sending the data, the recipient uses the sender's public key to verify the signature.

[0050] Digital signatures: In public-key cryptography, we can use a private key to represent a user's characteristics. When we encrypt data using the private key, it is equivalent to digitally signing the data using the user's characteristics.

[0051] Signature verification: In public-key cryptography, when we use the public key to decrypt signed data, we can verify whether the existing signature is authentic and valid.

[0052] AJAX Request: AJAX stands for Asynchronous JavaScript and XML. It's a technique for creating fast, dynamic web pages. AJAX allows you to send asynchronous requests from the browser to the server, enabling asynchronous updates to web pages. This means that parts of a web page can be updated without reloading the entire page. AJAX is not a new programming language, but rather a new way of combining existing standards.

[0053] Base64 values: Base64 is one of the common encoding methods used to transmit 8-bit byte code. Base64 is a method of representing binary data based on 64 printable characters.

[0054] Example 1

[0055] This invention discloses a method for generating and verifying image CAPTCHAs, such as... Figure 1 As shown, it includes the following steps:

[0056] Step S101: The client creates a session for submitting requests and caches the session in the browser's sandbox memory.

[0057] Before a user submits information through a browser using the client, the client needs to create a session. Specifically, before the user submits information through the browser using the client, the CreateSession interface of WASM in the sandbox is called via JavaScript to create and return a session, which is then cached in the browser's sandbox memory. This design at least helps to effectively identify and isolate each different submission request from the user, ensures that the session handle is used in a secure environment, and prevents it from being tampered with.

[0058] Step S102: The client receives a verification code request and generates a baseline verification code.

[0059] Specifically, upon receiving a user's verification code request, the GenerateCaptcha interface in WASM is called via JavaScript, passing the session as a parameter. The GenerateCaptcha interface first generates a visible string base verification code, userCode (generated internally and not externally), and then caches the mapping between the session and userCode in the browser's sandbox memory as key-value pairs. This design ensures a one-to-one correspondence between the session and the verification code.

[0060] In step S103, the client converts the baseline verification code into an image verification code for display.

[0061] Specifically, since the base CAPTCHA is in alphanumeric format, computer character rendering technology is used to convert it into an image before displaying it to the user. To facilitate the display of the image CAPTCHA, the Base64 value of the image CAPTCHA needs to be returned. Then, JavaScript dynamically changes the src attribute of the pre-defined img tag of the CAPTCHA image, and the browser renders the image CAPTCHA before displaying it to the user. Understandably, some distortion and obfuscation methods are generally added during the CAPTCHA display process to ensure that only the user can effectively recognize it.

[0062] In step S104, the client obtains the input user verification code and verifies it in the browser sandbox, then outputs the verification result.

[0063] After the user identifies and judges the text information in the image verification code, and enters the corresponding user verification code (captchaCode) in the designated input box (verification code submission unit), the client needs to verify the user verification code.

[0064] Specifically, after the user enters the verification code, the client calls the VerifyCaptcha interface in the WASM sandbox via JavaScript, passing in the session parameter and the user's verification code, captchaCode. Internally, the VerifyCaptcha interface first checks the mapping between the cached baseline verification code, userCode, and session to verify the correctness of the mapping. If incorrect, it returns an error; otherwise, it generates a current timestamp string, timeStamp. The client can use a pre-set private key, sm2privatekey, to sign the timeStamp and return the signature value, signData, indicating successful verification.

[0065] In general, client browsers have multiple windows. The verification process in multiple windows may interfere with each other because the sessions are not isolated. Therefore, it is important to ensure the correctness of the correspondence between the input user verification code (captchaCode) and the session to prevent the verification code from not matching the session.

[0066] In this embodiment of the invention, the image verification code generation and verification process are completed in the client browser, which avoids interaction between the client and the server, improves the efficiency of verification code generation and verification, and enhances user satisfaction.

[0067] Example 2

[0068] To further enhance the security of image CAPTCHA generation and verification, this embodiment also discloses another method for image CAPTCHA generation and verification, such as... Figure 2 As shown, it includes the following steps:

[0069] Step S201: Generate a key pair, wherein the private key is pre-set in the client browser sandbox and the public key is pre-set in the server.

[0070] In step S202, the client creates a session for submitting requests and caches the session in the browser's sandbox memory.

[0071] Before a user submits information through a browser using the client, the client needs to create a session. Specifically, before the user submits information through the browser using the client, the CreateSession interface of WASM in the sandbox is called via JavaScript to create and return a session, which is then cached in the browser's sandbox memory. This design at least helps to effectively identify and isolate each different submission request from the user, ensures that the session handle is used in a secure environment, and prevents it from being tampered with.

[0072] Step S203: The client receives a verification code request and generates a baseline verification code.

[0073] Specifically, upon receiving a user's verification code request, the GenerateCaptcha interface in WASM is called via JavaScript, passing in the parameter "session". The GenerateCaptcha interface first generates a visible string base verification code "userCode" (generated internally by the program and not displayed externally), and then caches the mapping between the session and the base verification code "userCode" in the browser sandbox memory as key-value pairs. This design ensures a one-to-one correspondence between the session and the verification code.

[0074] In step S204, the client converts the baseline verification code into an image verification code for display.

[0075] Specifically, since the base CAPTCHA is in alphanumeric format, it needs to be converted into an image before being displayed to the user. To return a convenient image CAPTCHA for easy display, the Base64 value of the image CAPTCHA needs to be returned. Then, the src attribute of the preset img tag of the CAPTCHA image needs to be dynamically changed using JavaScript, and the browser needs to render this image CAPTCHA before displaying it to the user.

[0076] Step S205: The client obtains the input user verification code and verifies it in the browser sandbox.

[0077] After the user identifies and judges the text information in the image verification code, and enters the corresponding user verification code (captchaCode) in the designated input box (verification code submission unit), the client needs to verify the user verification code.

[0078] Specifically, after the user enters the verification code, the client calls the VerifyCaptcha interface in the WASM sandbox via JavaScript, passing in the session parameter and the user's verification code, captchaCode. Internally, the VerifyCaptcha interface first checks the mapping between the cached baseline verification code, userCode, and session to verify the correctness of the mapping. If incorrect, it returns an error; otherwise, it generates a current timestamp string, timeStamp. The client can use a pre-set private key, sm2privatekey, to sign the timeStamp and return the signature value, signData, indicating successful verification.

[0079] In general, client browsers have multiple windows. The verification process in multiple windows may interfere with each other because the sessions are not isolated. Therefore, it is important to ensure the correctness of the correspondence between the input user verification code (captchaCode) and the session to prevent the verification code from not matching the session.

[0080] Step 206: The client sends the user-submitted data, the current timestamp string (timeStamp), and the signature value (signData) to the server, and receives the server's verification result of the signature value (signData) based on the current timestamp string (timeStamp) and the preset public key, and outputs the verification result.

[0081] Specifically, in practical applications, when a user needs to submit data, such as submitting a username and password during login, the server can verify whether the data to be submitted has passed a valid CAPTCHA verification mechanism. At this time, the client initiates an AJAX request, sending the user-submitted data, the current timestamp string `timeStamp`, and the signature value `signData` to the server. To prevent bypassing the entire verification mechanism by tampering with the client program, the server verifies the signature value `signData` based on the current timestamp string `timeStamp` and a pre-set public key.

[0082] This step is a signature verification application. The client uses its private key to sign the data and sends it to the server. The server uses its public key to verify the signature, that is, when decrypting the signed data using the public key, it verifies whether the existing signature is genuine and valid.

[0083] In this embodiment, the image verification code generation and verification process are completed within the client's browser, reducing the number of interactions between the client and the server, improving generation and verification efficiency, and enhancing user satisfaction. Furthermore, this embodiment reduces server computational overhead, lowers server load, and improves server service capabilities. Additionally, this embodiment uses digital signature technology based on public-key cryptography algorithms, ensuring that each data request undergoes image verification by the client before being processed, thus improving security and system availability.

[0084] To facilitate understanding, this embodiment of the invention also provides a schematic diagram illustrating the interaction between the user, client (client browser), and server (server) in a specific application of an image verification code generation and verification method, as shown below. Figure 3 As shown, the image CAPTCHA generation and verification method includes the following steps:

[0085] Preparation phase: Generate a key pair, in which the private key is pre-set in the client browser sandbox and the public key is pre-set on the server.

[0086] Step 2-1: To effectively identify and isolate each unique user submission request, a session needs to be created before the user uses the entire mechanism. Before submitting information through the browser using the client, the user calls the CreateSession interface in WASM via JavaScript.

[0087] Step 2-2: To ensure that the session handle is used in a secure environment and to prevent it from being tampered with, a session needs to be created and returned for this generation and verification process, and the session needs to be cached in the browser sandbox memory.

[0088] Steps 2-3: After receiving the user's verification code request, call the GenerateCaptcha interface in WASM via JavaScript, passing in the session parameter.

[0089] Steps 2-4: The GenerateCaptcha API first generates a visible string base verification code (userCode), and then caches the mapping between the session and the base verification code (userCode) in the browser sandbox memory as key-value pairs. This design ensures a one-to-one correspondence between the session and the verification code.

[0090] Steps 2-5, then return the Base64 value of the image verification code;

[0091] Steps 2-6: Dynamically change the src attribute of the preset img tag using JavaScript;

[0092] Steps 2-7: The browser renders this image verification code and displays it to the user;

[0093] Steps 2-8 are for completing the user's recognition and submission of the image verification code. The user recognizes and judges the text information in the image verification code, enters the corresponding user verification code (captchaCode) in the designated input box, and submits.

[0094] Steps 2-9 are for verifying the verification code. The submission function first needs to call the VerifyCaptcha interface in WASM via JavaScript, passing in the session parameter `session` and the user's verification code `captchaCode`.

[0095] Steps 2-10: To prevent discrepancies between the verification code and the session, the VerifyCaptcha interface first checks the mapping between the cached baseline verification code (userCode) and the session to determine the correctness of the mapping. If incorrect, an error is returned.

[0096] Step 2-11: If correct, generate the current timestamp value string "timeStamp" to use timestamp technology to prevent the problem of a CAPTCHA being repeatedly verified.

[0097] Step 2-12: Use the preset private key sm2privatekey to sign the current timestamp value string timeStamp and return the signature value signData to prevent the timestamp value from being tampered with externally.

[0098] Step 2-13: In order to verify whether the data to be submitted has passed the valid CAPTCHA verification mechanism, when the user submits data (such as login name and password), an AJAX request is initiated to send the user data to be submitted, the current timestamp value string timeStamp, and the signature value signData to the server.

[0099] Step 2-14: To prevent bypassing the verification mechanism by tampering with the client program, the server verifies the signature value signData based on the current timestamp string timeStamp and the public key.

[0100] Step 2-15: In order to inform the user whether the current data submission process has been successfully verified, the server will send the verification result to the client. If the verification fails, an error will be returned; if the verification is successful, the operation will be submitted and a submission success message will be returned.

[0101] Example 3

[0102] This invention also discloses a client, such as... Figure 4 As shown, it includes a session creation unit 101, a baseline verification code generation unit 102, a verification code display unit 103, and a verification code verification unit 104, wherein:

[0103] Session creation unit 101 is used to create a session for submitting a request and cache the session in the browser sandbox memory.

[0104] Specifically, before a user submits information through a browser using the client, the client needs to create a session. Specifically, before the user submits information through the browser using the client, the `CreateSession` interface of WASM in the sandbox is called via JavaScript to create and return a session, which is then cached in the browser's sandbox memory. This design at least helps to effectively identify and isolate each different user submission request, ensures that the session handle is used in a secure environment, and prevents tampering.

[0105] The baseline verification code generation unit 102 obtains the verification code request and generates the baseline verification code.

[0106] Specifically, upon receiving a user's verification code request, the GenerateCaptcha interface in WASM is called via JavaScript, passing the session as a parameter. The GenerateCaptcha interface first generates a visible string base verification code, userCode (generated internally and not externally), and then caches the mapping between the session and userCode in the browser's sandbox memory as key-value pairs. This design ensures a one-to-one correspondence between the session and the verification code.

[0107] The verification code display unit 103 is used to convert the baseline verification code into an image verification code for display.

[0108] Specifically, since the base CAPTCHA is in alphanumeric format, computer character rendering technology is used to convert it into an image before displaying it to the user. To facilitate the display of the image CAPTCHA, the Base64 value of the image CAPTCHA needs to be returned. Then, JavaScript dynamically changes the src attribute of the pre-defined img tag of the CAPTCHA image, and the browser renders the image CAPTCHA before displaying it to the user. Understandably, some distortion and obfuscation methods are generally added during the CAPTCHA display process to ensure that only the user can effectively recognize it.

[0109] The verification code verification unit 104 is used to obtain the input user verification code, perform verification code verification in the browser sandbox, and output the verification result.

[0110] After the user identifies and judges the text information in the image verification code, and enters the corresponding user verification code (captchaCode) in the designated input box (verification code submission unit), the client needs to verify the user verification code.

[0111] Specifically, after the user enters the verification code, the client calls the VerifyCaptcha interface in the WASM sandbox via JavaScript, passing in the session parameter and the user's verification code, captchaCode. Internally, the VerifyCaptcha interface first checks the mapping between the cached baseline verification code, userCode, and session to verify the correctness of the mapping. If incorrect, it returns an error; otherwise, it generates a current timestamp string, timeStamp. The client can use a pre-set private key, sm2privatekey, to sign the timeStamp and return the signature value, signData, indicating successful verification.

[0112] In general, client browsers have multiple windows. The verification process in multiple windows may interfere with each other because the sessions are not isolated. Therefore, it is important to ensure the correctness of the correspondence between the input user verification code (captchaCode) and the session to prevent the verification code from not matching the session.

[0113] In this embodiment of the invention, the image verification code generation and verification process are completed in the client browser, which avoids interaction between the client and the server, improves the efficiency of verification code generation and verification, and enhances user satisfaction.

[0114] Example 4

[0115] This invention also discloses another client, including a key pair generation unit 101', a session creation unit 102', a baseline verification code generation unit 103', a verification code display unit 104', a first verification unit 105', and a second verification unit 106':

[0116] The key pair generation unit 101' is used to generate a key pair, wherein the private key is preset in the client browser sandbox and the public key is preset in the server.

[0117] Session creation unit 102' is used to create a session for submitting a request and cache the session in the browser sandbox memory.

[0118] Specifically, before a user submits information through a browser using the client, the client needs to create a session. Specifically, before the user submits information through the browser using the client, the `CreateSession` interface of WASM in the sandbox is called via JavaScript to create and return a session, which is then cached in the browser's sandbox memory. This design at least helps to effectively identify and isolate each different user submission request, ensures that the session handle is used in a secure environment, and prevents tampering.

[0119] The baseline verification code generation unit 103' obtains the verification code request and generates the baseline verification code.

[0120] Specifically, upon receiving a user's verification code request, the GenerateCaptcha interface in WASM is called via JavaScript, passing the session as a parameter. The GenerateCaptcha interface first generates a visible string base verification code, userCode (generated internally and not externally), and then caches the mapping between the session and userCode in the browser's sandbox memory as key-value pairs. This design ensures a one-to-one correspondence between the session and the verification code.

[0121] The verification code display unit 104' is used to convert the baseline verification code into an image verification code for display.

[0122] Specifically, since the base CAPTCHA is in alphanumeric format, computer character rendering technology is used to convert it into an image before displaying it to the user. To facilitate the display of the image CAPTCHA, the Base64 value of the image CAPTCHA needs to be returned. Then, JavaScript dynamically changes the src attribute of the pre-defined img tag of the CAPTCHA image, and the browser renders the image CAPTCHA before displaying it to the user. Understandably, some distortion and obfuscation methods are generally added during the CAPTCHA display process to ensure that only the user can effectively recognize it.

[0123] The first verification unit 105' is used to obtain the input user verification code and perform verification code verification in the browser sandbox.

[0124] After the user identifies and judges the text information in the image verification code, and enters the corresponding user verification code (captchaCode) in the designated input box (verification code submission unit), the client needs to verify the user verification code.

[0125] Specifically, after the user enters the verification code, the client calls the VerifyCaptcha interface in the WASM sandbox via JavaScript, passing in the session parameter and the user's verification code, captchaCode. Internally, the VerifyCaptcha interface first checks the mapping between the cached baseline verification code, userCode, and session to verify the correctness of the mapping. If incorrect, it returns an error; otherwise, it generates a current timestamp string, timeStamp. The client can use a pre-set private key, sm2privatekey, to sign the timeStamp and return the signature value, signData, indicating successful verification.

[0126] In general, client browsers have multiple windows. The verification process in multiple windows may interfere with each other because the sessions are not isolated. Therefore, it is important to ensure the correctness of the correspondence between the input user verification code (captchaCode) and the session to prevent the verification code from not matching the session.

[0127] The second verification unit 106' sends the user-submitted data, the current timestamp value string (timeStamp), and the signature value to the server, and receives the server's verification result based on the current timestamp value string and the preset public key, and outputs the verification result.

[0128] Specifically, in practical applications, when a user needs to submit data, such as submitting a username and password during login, the server can verify whether the data to be submitted has passed a valid CAPTCHA verification mechanism. At this time, the client initiates an AJAX request, sending the user-submitted data, the current timestamp string `timeStamp`, and the signature value `signData` to the server. To prevent bypassing the entire verification mechanism by tampering with the client program, the server verifies the signature value `signData` based on the current timestamp string `timeStamp` and a pre-set public key.

[0129] This step is a signature verification application. The client uses its private key to sign the data and sends it to the server. The server uses its public key to verify the signature, that is, when decrypting the signed data using the public key, it verifies whether the existing signature is genuine and valid.

[0130] In this embodiment, the image verification code generation and verification process are completed within the client's browser, reducing the number of interactions between the client and the server, improving generation and verification efficiency, and enhancing user satisfaction. Furthermore, this embodiment reduces server computational overhead, lowers server load, and improves server service capabilities. Additionally, this embodiment uses digital signature technology based on public-key cryptography algorithms, ensuring that each data request undergoes image verification by the client before being processed, thus improving security and system availability.

[0131] Example 5

[0132] This invention also discloses an image verification code generation and verification device, including a client and a server. The client is the same as described in Embodiment 4. The server receives user-submitted data, a current timestamp value string, and a signature value sent by a second verification unit. It then verifies the signature value based on the current timestamp value string and a preset public key, and sends the verification result to the client. This includes returning an error message if verification fails; and submitting the operation and returning a success message if verification is successful. The specific workflow of this image verification code generation and verification device is the same as described in Embodiments 2 and 4 above, and will not be repeated here.

[0133] In the detailed description above, various features are combined together in a single embodiment to simplify this disclosure. This approach to disclosure should not be construed as reflecting an intention that embodiments of the claimed subject matter require more features than are explicitly stated in each claim. Rather, as reflected in the appended claims, the invention is presented with fewer features than all of the features in a single disclosed embodiment. Therefore, the appended claims are hereby explicitly incorporated into the detailed description, wherein each claim stands alone as a preferred embodiment of the invention.

[0134] The foregoing description includes examples of one or more embodiments. It is certainly impossible to describe all possible combinations of components or methods in order to describe the above embodiments, but those skilled in the art will recognize that further combinations and arrangements of the various embodiments are possible. Therefore, the embodiments described herein are intended to cover all such changes, modifications, and variations falling within the scope of the appended claims. Furthermore, the term "comprising" as used in the specification or claims is interpreted in a manner similar to the term "including," as interpreted when "including" is used as a conjunction in the claims. Additionally, the use of any term "or" in the specification of the claims is intended to mean "non-exclusive or."

Claims

1. A method for generating and verifying image CAPTCHAs, characterized in that, Includes the following steps: The client calls the CreateSession interface of WASM in the sandbox via JavaScript to create and return a session, which is then cached in the browser's sandbox memory. The system requests a verification code and calls the GenerateCaptcha interface in WASM via JavaScript, passing the session as a parameter. It generates a baseline verification code and caches the correspondence between the session and the baseline verification code in the browser sandbox memory in the form of key-value pairs. The baseline verification code is in alphanumeric and / or numeric form. Convert the standard CAPTCHA into an image CAPTCHA for display. The system retrieves the input user verification code and calls the VerifyCaptcha interface in the WASM sandbox via JavaScript, passing in the session and user verification code as parameters. The VerifyCaptcha interface determines the correctness of the correspondence between the input user verification code and the session based on the cached baseline verification code and session correspondence, performs verification code validation in the browser sandbox, and outputs the verification result.

2. A method for generating and verifying image CAPTCHAs, characterized in that, Includes the following steps: The client generates a key pair, in which the private key is pre-set in the client's browser sandbox and the public key is pre-set on the server; The client calls the CreateSession interface of WASM in the sandbox via JavaScript to create a session for submitting requests and cache the session in the browser sandbox memory; The system retrieves a verification code request, calls the GenerateCaptcha interface in WASM via JavaScript, passes the session as a parameter, generates a baseline verification code, and caches the correspondence between the session and the baseline verification code in the browser sandbox memory in the form of key-value pairs. Convert the standard CAPTCHA into an image CAPTCHA for display. The input user verification code is obtained by calling the VerifyCaptcha interface in the WASM sandbox using JavaScript, passing in the session and user verification code as parameters. The VerifyCaptcha interface determines the correctness of the correspondence between the input user verification code and the session based on the cached baseline verification code and session correspondence, and performs verification code verification in the browser sandbox. If the verification is successful, a current timestamp value string is generated, the current timestamp value string is signed using a preset private key, and the signature value is returned. The client sends the user-submitted data, the current timestamp value string, and the signature value to the server, and receives the server's verification result based on the current timestamp value string and the preset public key, and outputs the verification result.

3. The method as described in claim 1 or 2, characterized in that, The client converts the baseline CAPTCHA into an image CAPTCHA for display, and also includes: Convert the standard CAPTCHA into an image CAPTCHA; Return the Base64 value of the image verification code; The src attribute of the preset img tag for the verification code is dynamically changed using JavaScript, and the browser renders the image verification code before displaying it to the user.

4. The method as described in claim 1 or 2, characterized in that, The VerifyCaptcha interface, based on the cached baseline verification code and session mapping relationship, also determines the correctness of the mapping relationship between the incoming user verification code and the session by: If incorrect, an error message will be returned; Otherwise, generate the current timestamp value string, sign the current timestamp value string using the preset private key, and return the signed value.

5. The method as described in claim 2, characterized in that, The client uses an AJAX request to send the user-submitted data, the current timestamp string, and the signature value to the server.

6. A client application, characterized in that, It includes a session creation unit, a baseline verification code generation unit, a verification code display unit, and a verification code verification unit, wherein: The session creation unit is used by the client to call the CreateSession interface of WASM in the sandbox via JavaScript, create and return a session, and cache the session in the browser sandbox memory; The baseline CAPTCHA generation unit obtains the CAPTCHA request, calls the GenerateCaptcha interface in WASM via JavaScript, passes the session as a parameter, generates a baseline CAPTCHA, and caches the correspondence between the session and the baseline CAPTCHA in the browser sandbox memory in the form of key-value pairs, wherein the baseline CAPTCHA is in alphanumeric form. The verification code display unit is used to convert the baseline verification code into an image verification code for display. The CAPTCHA verification unit is used to obtain the input user CAPTCHA. It calls the VerifyCaptcha interface in the WASM sandbox via JavaScript, passing in the session and user CAPTCHA parameters. The VerifyCaptcha interface determines the correctness of the correspondence between the input user CAPTCHA and the session based on the cached baseline CAPTCHA and session correspondence, performs CAPTCHA verification in the browser sandbox, and outputs the verification result.

7. A client application, characterized in that, It includes a key pair generation unit, a session creation unit, a baseline verification code generation unit, a verification code display unit, a first verification unit, and a second verification unit, wherein: A key pair generation unit is used to generate a key pair, wherein the private key is pre-set in the client browser sandbox and the public key is pre-set in the server; The session creation unit is used by the client to call the CreateSession interface of WASM in the sandbox via JavaScript to create a session for submitting requests and cache the session in the browser sandbox memory; The baseline CAPTCHA generation unit is used to obtain CAPTCHA requests, call the GenerateCaptcha interface in WASM via JavaScript, pass the session as a parameter, generate a baseline CAPTCHA, and cache the correspondence between the session and the baseline CAPTCHA in the browser sandbox memory in the form of key-value pairs. The verification code display unit is used to convert the baseline verification code into an image verification code for display. The first verification unit is used to call the VerifyCaptcha interface in the WASM sandbox via JavaScript, passing in the parameters session and user verification code. The VerifyCaptcha interface determines the correctness of the correspondence between the passed user verification code and session based on the cached baseline verification code and session correspondence, and performs verification code verification in the browser sandbox; if the verification is correct, it generates the current timestamp value string, signs the current timestamp value string using a preset private key, and returns the signature value. The second verification unit is used to send the current timestamp value string and the signature value to the server, receive the server's verification result of the signature value based on the current timestamp value string and the preset public key, and output the verification result.

8. A device for generating and verifying image verification codes, characterized in that, The system includes a client and a server. The client is the client described in claim 7. The server is used to receive the current timestamp value string and the signature value sent by the second verification unit, and to verify the signature value according to the current timestamp value string and the preset public key, and to send the verification result to the client.

Citation Information

Patent Citations

  • Method for processing verification codes of pages, device and terminal

    CN102469091A

  • Verification method and system for graphic verification code generated by client

    CN114584327A