Text click verification code generation method, device, terminal device and storage medium
By generating a synthetic image with missing text edges, the problems of existing verification codes being easy to crack and having poor user experience are solved, and a verification code generation method that is difficult to crack and user-friendly is realized.
Patent Information
- Application Number
- CN202411255306.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2044-09-09
AI Technical Summary
Existing text-based verification codes have limited defense capabilities against automated attacks, and excessive distortion leads to a poor user experience, especially for visually impaired users.
Generate a text image with a white background and black fonts. Use the text generation technology and mask redrawing method to form a synthetic image. The edges of the text are missing, making it difficult for automated tools to recognize but easy for humans to recognize.
It improves the defense capability of verification codes, reduces the difficulty of automated cracking, and improves the user experience, especially the friendliness for visually impaired users.
Smart Images

Figure CN119293773B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of verification code recognition, and in particular to a method, device, terminal equipment and storage medium for generating a text-click verification code. Background Art
[0002] Existing text-based verification codes offer limited protection against automated attacks: Although text-based verification codes are designed to prevent automated attacks, technological advancements, including machine learning and image recognition, may make such verification code systems more vulnerable to automated tools, such as WeChat's text extraction function. Some verification systems introduce excessive distortion to increase the difficulty of cracking. Excessive distortion can require additional time and effort to accurately identify and click the text in the verification code, which can be distracting and degrade the user experience, particularly for visually impaired users. Summary of the Invention
[0003] The present invention provides a method, apparatus, terminal device and storage medium for generating a text-click verification code, so as to solve the technical problem in the prior art of adding excessive distortion to the question, resulting in poor user experience.
[0004] In order to solve the above technical problems, an embodiment of the present invention provides a method for generating a text-click verification code, comprising:
[0005] Randomly select one or more words from a preset Chinese phrase database as a vocabulary group;
[0006] Generating a text image with a white background and black font according to the vocabulary group;
[0007] Generate a content image based on the vocabulary group using text-based graph technology;
[0008] Using the text image as a mask image and the content image as a target image, the mask is redrawn to generate a composite image; wherein the edges of the text in the composite image are missing;
[0009] The vocabulary group and the composite image are uploaded to a text click verification code database.
[0010] As a preferred solution, generating a text image with a white background and black font based on the vocabulary group includes:
[0011] Counting the number of characters in the vocabulary group;
[0012] Generate a white background image, and divide the background image into a corresponding number of areas according to the number of characters; wherein no two areas overlap;
[0013] Scrambling the order of the characters in the vocabulary group to generate a new character sequence;
[0014] According to the character sequence, a corresponding character in black font is generated in each of the areas in turn.
[0015] As a preferred solution, the font parameter settings in the text image include:
[0016] Set the font type to Microsoft YaHei;
[0017] Set the font style to bold;
[0018] Set the font size to 256;
[0019] Set the vertical font scaling to 150%;
[0020] Set the horizontal font scaling to 130%.
[0021] As a preferred solution, the method of generating a content image based on the vocabulary group using text-based graph technology includes:
[0022] The words in the vocabulary group are used as prompt words, and the text image function of the Stab le Diffus ion XL model is used to generate content images.
[0023] As a preferred solution, the step of using the text image as a mask image and the content image as a target image to perform mask redrawing to generate a composite image includes:
[0024] Overlapping the mask image and the target image;
[0025] The mask image and the target image are input into a mask redrawing tool so that the overlapping portion of the target image and the black portion of the mask image is modified, and a composite image is output.
[0026] As a preferred solution, the parameter configuration of the mask redrawing tool includes:
[0027] Set the image sampling steps to 32;
[0028] Set the image sampler to DPM++2M Karras;
[0029] Set the composite image resolution to 1024×1024;
[0030] Set the synthetic image generation model to sd_x l_base_1.0;
[0031] Set the redraw amplitude to 0.8;
[0032] Set up a Tuya Control Net module and a Deep Control Net module;
[0033] Set the model used by the Tuya Control Net module to sai_x l_sketch_256l ora;
[0034] The model used by the depth Control Net module is set to sai_x l_depth_256l ora.
[0035] Based on the above embodiment, another embodiment of the present invention provides a text-click verification code generation device, comprising: a text acquisition module, a mask image generation module, a target image generation module, a mask redrawing module and a data upload module;
[0036] The text acquisition module is used to randomly select one or more words from a preset Chinese phrase database as a vocabulary group;
[0037] The mask image generation module is used to generate a text image with a white background and black font according to the vocabulary group;
[0038] The target image generation module is used to generate a content image based on the vocabulary group using the text-based image technology;
[0039] The mask redrawing module is configured to use the text image as a mask image and the content image as a target image to perform mask redrawing to generate a composite image; wherein the edges of the text in the composite image are missing;
[0040] The data uploading module is used to upload the vocabulary group and the composite image to a text click verification code database.
[0041] Based on the above embodiments, another embodiment of the present invention provides a terminal device, which includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the text-click verification code generation method described in the above embodiment of the invention is implemented.
[0042] Based on the above embodiment, another embodiment of the present invention provides a storage medium, which includes a stored computer program, wherein when the computer program is running, the device where the storage medium is located is controlled to execute the text-click verification code generation method described in the above embodiment of the invention.
[0043] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0044] The present invention generates a text image and a content image based on a randomly selected vocabulary group; then the text image is used as a mask image, and the content image is used as a target image, and the mask is redrawn to generate a composite image; finally, the vocabulary group and the composite image are uploaded to a text click verification code database. Although the text in the composite image generated by the present invention does not have any distortion effect, because the edges of the text are missing in the image after the mask is redrawn, the text and the image can be merged, which makes it impossible for automated text tools to recognize these texts. However, human cognitive function has a principle of completeness and closure tendency for graphics and backgrounds, so that even if our brain sees incomplete edges, it tends to see a complete graphic. Therefore, the present invention takes into account the advantages of being difficult to crack and user-friendly at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 This is a flow chart of a method for generating a text-click verification code according to an embodiment of the present invention;
[0046] Figure 2 is a text image generated in one embodiment of the present invention;
[0047] Figure 3 is a content picture generated in one embodiment of the present invention;
[0048] Figure 4 is a composite picture generated in one embodiment of the present invention;
[0049] Figure 5 It is a structural diagram of a device for generating a text-click verification code provided by one embodiment of the present invention. DETAILED DESCRIPTION
[0050] To make the objectives, technical solutions, and advantages of this application more clear, the technical solutions in this application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making any creative efforts are within the scope of protection of this application.
[0051] Unless otherwise defined, all technical and scientific terms used herein have the same meanings as commonly understood by those skilled in the art to which this application belongs. The terms used herein are for the purpose of describing specific embodiments only and are not intended to limit this application. The terms "including" and "having" and any variations thereof in the specification and claims of this application and the accompanying drawings are intended to cover non-exclusive inclusions. "Several" means two or more.
[0052] References herein to "embodiments" mean that a particular feature, structure, or characteristic described in connection with the embodiments may be included in at least one embodiment of the present application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it constitute an independent or alternative embodiment that is mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0053] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0054] Example 1
[0055] Please refer to Figure 1 , which is a flow chart of a method for generating a text-click verification code according to an embodiment of the present invention, including:
[0056] S1. Randomly select one or more words from a preset Chinese phrase database as a vocabulary group.
[0057] It should be noted that the Chinese phrase database can be manually imported into a batch of selected phrases, or a batch of phrases can be automatically generated and imported using a large language model.
[0058] In step S1, one or more words are randomly selected from the Chinese phrase data as a vocabulary group, for example, milk, bread.
[0059] S2. Generate a text image with a white background and black font based on the vocabulary group.
[0060] In step S2, a text image with a white background and black font is automatically generated using a Photoshop script based on the vocabulary group.
[0061] It should be noted that the pixels of the text image are 1024×1024.
[0062] In a preferred embodiment, generating a text image with a white background and black font based on the vocabulary group includes:
[0063] Counting the number of characters in the vocabulary group;
[0064] Generate a white background image, and divide the background image into a corresponding number of areas according to the number of characters; wherein no two areas overlap;
[0065] Scrambling the order of the characters in the vocabulary group to generate a new character sequence;
[0066] According to the character sequence, a corresponding character in black font is generated in each of the areas in turn.
[0067] In this embodiment, the number of characters in a phrase is limited to 3-4.
[0068] Count the number of characters in the vocabulary group. For example, the number of characters in "milk bread" is 4.
[0069] Generate a white background image with a size of 1024×1024. Divide the background image into four different areas: the first area, the second area, the third area, and the fourth area. These four areas do not overlap with each other.
[0070] The order of the words in the word picture can be arranged arbitrarily. Shuffle the words in the vocabulary group to generate a new word sequence. For example, the possible word sequences for the vocabulary group [milk, bread] are: milk bread, milk noodles, cow noodles, cow bread milk, cow bread milk noodles, cow bread milk noodles, cow bread milk, cow bread, cow bread noodles, milk noodles cow bread, milk bread cow, milk bread cow noodles, milk bread cow, milk bread cow noodles, milk bread cow, milk bread cow, milk bread cow, milk bread cow, milk bread cow, milk bread cow, milk bread cow, milk bread cow, bread cow, bread cow, bread milk, bread cow ...
[0071] Taking the text sequence "milk bread" as an example, according to the first character "cow" in the text sequence, a corresponding black text image is generated in the first area; according to the second character "milk", a corresponding black text image is generated in the second area; according to the third character "noodles", a corresponding black text image is generated in the third area; according to the fourth character "package", a corresponding black text image is generated in the fourth area, and the result is as follows: Figure 2 Text image shown.
[0072] Although the generated text images are in different areas, we should try to ensure that there is a certain distance between the text graphics and a certain distance between the text graphics and the edges of the background image.
[0073] While the text in the composite image generated by the text-click verification code generation method provided by the present invention is not distorted, the text edges are missing in the masked image, allowing the text and image to blend, making it difficult for automated text recognition tools to recognize the text. Human cognition tends to perceive completeness and closure between graphics and backgrounds, leading our brains to perceive a complete image even when seeing incomplete edges. Therefore, the present invention combines the advantages of being difficult to crack and user-friendly.
[0074] In a preferred embodiment, the first area is the upper left area of the background image; the second area is the upper right area of the background image; the third area is the lower left area of the background image; and the fourth area is the lower right area of the background image.
[0075] In this embodiment, the white background image is divided into four equal areas: upper left, upper right, lower left and lower right. The upper left area is the first area, the upper right area is the second area, the lower left area is the third area, and the lower right area is the fourth area.
[0076] In a preferred embodiment, the font parameter settings in the text image include:
[0077] Set the font type to Microsoft YaHei;
[0078] Set the font style to bold;
[0079] Set the font size to 256;
[0080] Set the vertical font scaling to 150%;
[0081] Set the horizontal font scaling to 130%.
[0082] In this embodiment, the font in the text image is required to be conspicuous enough, so the font type is set to Microsoft YaHei, the style is set to bold, the size is set to 256, the vertical scale ratio is set to 150%, and the horizontal scale ratio is set to 130%. This setting makes the composite image generated by the subsequent mask redrawing easy for users to recognize.
[0083] S3. Generate a content image based on the vocabulary group using text-based graph technology.
[0084] In a preferred embodiment, generating a content image based on the vocabulary group using text graph technology includes:
[0085] The words in the vocabulary group are used as prompt words, and the text image function of the Staple Diffusion XL model is used to generate content images.
[0086] In this embodiment, the words "milk" and "bread" in the vocabulary group are used as prompt words, and the text map function of the Staple Diffusion XL model is used to generate the following Figure 3 Content image shown.
[0087] It should be noted that content images are intelligently generated based on the meaning of words, and the image content is related to the meaning of the words.
[0088] S4. Using the text image as a mask image and the content image as a target image, redrawing the mask to generate a composite image; wherein the edges of the text in the composite image are missing.
[0089] In a preferred embodiment, the step of using the text image as a mask image and the content image as a target image to perform mask redrawing to generate a composite image includes:
[0090] Overlapping the mask image and the target image;
[0091] The mask image and the target image are input into a mask redrawing tool so that the overlapping portion of the target image and the black portion of the mask image is modified, and a composite image is output.
[0092] It's important to note that a mask is used to define which parts of an image should be edited, preserved, or displayed. The black areas (i.e., the text areas) on the mask determine which parts of the target image will be redrawn or modified. Typically, white areas on the mask indicate the corresponding parts of the target image to be preserved or displayed, while black areas indicate the corresponding parts to be hidden or modified.
[0093] In this embodiment, the content image is the target image, and the target image refers to the image affected and modified by the mask. In the process of modifying the target image, the mask image is used to guide the editing of the target image, and the following will be generated in the end. Figure 4 Composite image shown.
[0094] It should also be noted that the mask redrawing function used in the present invention processes the edges of the mask image to cause missing or blurred edges. A commonly used processing method is to feather the mask to blur the boundary between the black and white areas of the mask image, resulting in blurred edges and missing edges in the resulting composite image.
[0095] In a preferred embodiment, the parameter configuration of the mask redrawing tool includes:
[0096] Set the image sampling steps to 32;
[0097] Set the image sampler to DPM++2M Karras;
[0098] Set the composite image resolution to 1024×1024;
[0099] Set the synthetic image generation model to sd_x l_base_1.0;
[0100] Set the redraw amplitude to 0.8;
[0101] Set up a Tuya Control Net module and a Deep Control Net module;
[0102] Set the model used by the Tuya Control Net module to sai_x l_sketch_256l ora;
[0103] The model used by the depth Control Net module is set to sai_x l_depth_256l ora.
[0104] In this embodiment, the image sampling deployment specifies the number of sampling steps when generating an image, which is set to 32. The image sampler specifies the sampler used to generate the image, which is set to DPM++2M Karras. The synthetic image resolution defines the size of the generated image and is set to 1024x1024. The synthetic image generation model specifies the model used to generate the image and is set to "sd_xl_base_1.0". The redraw amplitude determines the degree of modification to the target image during the mask redrawing process and is set to 0.8. Two different Control Net modules and their corresponding models are specified, one is the Graffiti Control Net module and the other is the Depth Control Net module. The Graffiti Control Net module is set to the sai_x l_sketch_256l ora model, and the Depth Control Net module is set to the sai_x l_sketch_256l ora model.
[0105] S5. Upload the vocabulary group and the composite image to a text-click verification code database.
[0106] It should be noted that the method of using the text click verification code includes:
[0107] Select a composite image and a corresponding vocabulary group from the text click verification code database;
[0108] Randomly adjust the order of the characters in the vocabulary group to obtain a character sequence as the verification code sequence;
[0109] Display the composite image to the user and wait for the user to click on the area corresponding to different text in the composite image;
[0110] Obtain the text sequence selected by the user according to the user's click order as the sequence to be verified;
[0111] Compare the verification code sequence with the sequence to be verified. If the text sequences are consistent, the verification passes, otherwise it fails.
[0112] Example 2
[0113] Please refer to Figure 5 , is a structural diagram of a text-click verification code generation device provided by an embodiment of the present invention, comprising: a text acquisition module, a mask image generation module, a target image generation module, a mask redrawing module, and a data upload module;
[0114] The text acquisition module is used to randomly select one or more words from a preset Chinese phrase database as a vocabulary group;
[0115] The mask image generation module is used to generate a text image with a white background and black font according to the vocabulary group;
[0116] The target image generation module is used to generate a content image based on the vocabulary group using the text-based image technology;
[0117] The mask redrawing module is configured to use the text image as a mask image and the content image as a target image to perform mask redrawing to generate a composite image; wherein the edges of the text in the composite image are missing;
[0118] The data uploading module is used to upload the vocabulary group and the composite image to a text click verification code database.
[0119] Example 3
[0120] Accordingly, an embodiment of the present invention provides a terminal device, which includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, it implements the text-click verification code generation method described in the above-mentioned embodiment of the invention.
[0121] Example 4
[0122] Accordingly, an embodiment of the present invention provides a storage medium, which includes a stored computer program, wherein when the computer program is running, the device where the storage medium is located is controlled to execute the text-click verification code generation method described in the above-mentioned embodiment of the invention.
[0123] It should be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed across multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. In addition, in the drawings of the device embodiments provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines. A person of ordinary skill in the art can understand and implement the present invention without inventive work.
[0124] Those skilled in the art will clearly understand that for the sake of convenience and brevity, the specific working process of the device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0125] The terminal device may be a computing device such as a desktop computer, a notebook computer, a PDA, a cloud server, etc. The terminal device may include, but is not limited to, a processor and a memory.
[0126] The processor may be a central processing unit (CPU), or other general-purpose processors, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the device, and various parts of the entire device are connected using various interfaces and lines.
[0127] The memory can be used to store the computer program, and the processor realizes various functions of the device by running or executing the computer program stored in the memory and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application required for a function, etc.; the data storage area can store data created according to the use of the mobile phone, etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Med ia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage device.
[0128] The storage medium is a storage medium in which the computer program is stored. When the computer program is executed by the processor, the steps of each of the above-mentioned method embodiments can be implemented. The computer program includes computer program code, which can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0129] The above is a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications are also considered to be within the scope of protection of the present invention.
Claims
1. A method for generating a text-click verification code, characterized in that: include: Randomly select one or more words from a preset Chinese phrase database as a vocabulary group; Generating a text image with a white background and black font according to the vocabulary group; Generate a content image based on the vocabulary group using text-based graph technology; Using the text image as a mask image and the content image as a target image, the mask is redrawn to generate a composite image; wherein the edges of the text in the composite image are missing; The vocabulary group and the composite image are uploaded to a text click verification code database.
2. The method for generating a text-click verification code according to claim 1, wherein: Generating a text image with a white background and black font based on the vocabulary group includes: Counting the number of characters in the vocabulary group; Generate a white background image, and divide the background image into a corresponding number of areas according to the number of characters; wherein no two areas overlap; Scrambling the order of the characters in the vocabulary group to generate a new character sequence; According to the character sequence, a corresponding character in black font is generated in each of the areas in turn.
3. The method for generating a text-click verification code according to claim 1, wherein: The font parameter settings in the text image include: Set the font type to Microsoft YaHei; Set the font style to bold; Set the font size to 256; Set the vertical font scaling ratio to 150%; Set the horizontal font scaling to 130%.
4. The method for generating a text-click verification code according to claim 1, wherein: Generating a content image based on the vocabulary group using text-based graph technology includes: The words in the vocabulary group are used as prompt words, and the text image function of the Stable Diffusion XL model is used to generate content images.
5. The method for generating a text-click verification code according to claim 1, wherein: The step of using the text image as a mask image and the content image as a target image to perform mask redrawing to generate a composite image includes: Overlapping the mask image and the target image; The mask image and the target image are input into a mask redrawing tool to modify the overlapping portion of the target image and the black portion of the mask image, and output a composite image.
6. The method for generating a text-click verification code according to claim 5, wherein: The parameter configuration of the mask redrawing tool includes: Set the image sampling steps to 32; Set the image sampler to DPM++ 2M Karras; Set the composite image resolution to 1024×1024; Set the synthetic image generation model to sd_xl_base_1.0; Set the redraw amplitude to 0.8; Set up a Tuya ControlNet module and a Deepin ControlNet module; Set the model used by the Tuya ControlNet module to sai_xl_sketch_256lora; The model used by the depth ControlNet module is set to sai_xl_depth_256lora.
7. A device for generating a text-click verification code, characterized in that: include: Text acquisition module, mask image generation module, target image generation module, mask redrawing module and data upload module; The text acquisition module is used to randomly select one or more words from a preset Chinese phrase database as a vocabulary group; The mask image generation module is used to generate a text image with a white background and black font according to the vocabulary group; The target image generation module is configured to generate a content image based on the vocabulary group using a text-based image technology; The mask redrawing module is configured to use the text image as a mask image and the content image as a target image to perform mask redrawing to generate a composite image; wherein the edges of the text in the composite image are missing; The data uploading module is used to upload the vocabulary group and the composite image to a text click verification code database.
8. A terminal device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, the method for generating a text-click verification code according to any one of claims 1 to 6 is implemented.
9. A storage medium, characterized in that: The storage medium includes a stored computer program, wherein when the computer program is running, the device where the storage medium is located is controlled to execute the text-click verification code generation method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Click verification code identification method and device, and user terminal
CN108182437A
Click verification code recognition method and device, computer equipment and storage medium
CN111737548A
Multi-element semantic verification code and generation method thereof
CN116451207A