Method and device for generating verification code

By generating reference and target images for CAPTCHAs using a large model and applying transformation processing to the strings, the problem of existing CAPTCHAs being easily cracked is solved, achieving low-cost and high-reliability CAPTCHA generation.

CN121834784APending Publication Date: 2026-04-10ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-11
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

Existing text-based CAPTCHAs suffer from high generation and defense costs and are easily compromised by multimodal large-scale models.

Method used

By using a large model to generate reference and target images corresponding to the prompt questions, and applying special transformation processing to the strings in the reference images, the multimodal large model is induced to generate recognition illusions and generate incorrect images to enhance the defense capabilities of CAPTCHAs.

Benefits of technology

It significantly improves the reliability and defense capabilities of CAPTCHAs, reduces generation costs, and is user-friendly without increasing operational difficulty.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121834784A_ABST
    Figure CN121834784A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a verification code generation method and device, and the method comprises the steps: inputting a target character string into a large model, enabling the large model to generate a reference picture containing the target character string for a preset target problem, and enabling the target problem to be at least used for prompting a user to generate a verification code in each target picture, and selecting a matched picture of which the character string is matched with the target character string. And performing conversion processing on the target character string to obtain a first character string. And inputting the first character string into the large model to generate a first picture containing the first character string for the target question, and classifying the first picture into each target picture. And generating a verification code based on the target problem, the reference picture and each target picture.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] One or more embodiments of the present specification relate to the field of computer technology, and in particular, to a method and apparatus for generating a verification code. BACKGROUND

[0002] A verification code is a security verification mechanism used to distinguish between real users and automated programs, which requires the visitor to complete a specified task to confirm identity, thereby preventing automated abuse of websites or services.

[0003] Currently, there are various forms of verification codes, among which the most common is the text point selection verification code. This type of verification code usually uses ControlNet technology to fuse text with picture backgrounds, and the user needs to click on the specified text in the correct order to complete the verification. Generally, the system will provide three texts to be clicked, and the verification result depends on whether the user's click position and order are accurate. However, when generating a verification code using ControlNet technology, a font library suitable for ControlNet needs to be constructed, and new words need to be added regularly, which increases the cost of generating the verification code. In addition, the current verification code has poor defense capabilities. SUMMARY

[0004] One or more embodiments of the present specification describe a method and apparatus for generating a verification code, which can generate a high-reliability verification code at a lower cost.

[0005] In a first aspect, a method for generating a verification code is provided, comprising:

[0006] inputting a target string into a large model to generate a reference picture containing the target string for a preset target question; the target question is used to prompt the user to select a matching picture containing a string matching the target string from each target picture;

[0007] transforming the target string to obtain a first string; the transformation includes any of the following: deleting duplicate characters, adding the same characters, and plural transformation;

[0008] inputting the first string into the large model to generate a first picture containing the first string for the target question; and classifying the first picture into the target pictures;

[0009] generating a verification code based on the target question, the reference picture, and the target pictures.

[0010] In a second aspect, an apparatus for generating a verification code is provided, comprising:

[0011] The input unit is configured to input a target string into a large model, so that the large model generates a reference picture containing the target string in response to a preset target question; the target question is used to prompt a user to select a matching picture containing a string matching the target string from the target pictures.

[0012] The transformation unit is configured to perform transformation processing on the target string to obtain a first string; the transformation processing includes any one of the following: deleting duplicate characters, adding identical characters, and plural transformation.

[0013] The input unit is further configured to input the first string into the large model, so that the large model generates a first picture containing the first string in response to the target question; and the first picture is classified into the target pictures.

[0014] The generation unit is configured to generate a verification code based on the target question, the reference picture, and the target pictures.

[0015] In a third aspect, a computer storage medium is provided, and the computer storage medium stores a computer program. When the computer program is executed in a computer, the computer program causes the computer to execute the method in the first aspect.

[0016] In a fourth aspect, a computing device is provided, and the computing device includes a memory and a processor. The memory stores executable code, and the processor executes the executable code to implement the method in the first aspect.

[0017] The method for generating a verification code provided by one or more embodiments of the present specification generates a reference picture corresponding to a prompt question and a target picture (hereinafter referred to as an "error picture") that does not match the reference picture by using a large model, which can effectively reduce the generation cost of the verification code. In addition, the present solution applies special transformation processing to the string in the reference picture, which can easily induce a multi-modal large model to produce an identification illusion and generate a string in the error picture. In this way, the ability of the verification code to resist attacks by multi-modal large models can be significantly enhanced, thereby improving the reliability of the verification code. BRIEF DESCRIPTION OF DRAWINGS

[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present specification, the following will briefly introduce the drawings needed to be used in the embodiment description. Obviously, the drawings in the following description are only some embodiments of the present specification, and other drawings can also be obtained by those skilled in the art without creative labor.

[0019] Figure 1 The schematic diagram of the implementation scenario of an embodiment disclosed in the present specification;

[0020] Figure 2A flow chart of a method of generating a verification code according to one embodiment of the present specification is shown.

[0021] Figure 3 A schematic diagram of a verification code in one example of the present specification is shown.

[0022] Figure 4 A schematic diagram of a method of generating a verification code in one example of the present specification is shown.

[0023] Figure 5 A schematic diagram of an apparatus for generating a verification code according to one embodiment of the present specification is shown. DETAILED DESCRIPTION

[0024] The solutions provided in the present specification will be described below with reference to the accompanying drawings.

[0025] With the recent rapid progress of large language models and multi-modal large models in understanding and reasoning capabilities, the current verification code has been completely cracked by multi-modal large models, even without fine-tuning the multi-modal large models, the verification code can still be successfully cracked. To this end, the following three verification code enhancement methods are proposed:

[0026] First, the text in the verification code does not use regular script, and the text is inverted and rotated to increase the difficulty of attack.

[0027] Second, increase the fusion strength of the text and the background picture, so that the text is hidden deeper in the background picture.

[0028] Third, more text is added in the verification code as interference items.

[0029] However, the enhanced verification code is usually very unfriendly to users with poor eyesight, and at the same time increases the operation difficulty of normal users.

[0030] Therefore, the present solution proposes to generate the verification code by means of an artificial intelligence generated content (AIGC) model. Specifically, the AIGC is used to generate a reference picture corresponding to a prompt question and each target picture (including a correct picture matching the reference picture and an incorrect picture not matching the reference picture). In this way, the attacker can be prevented from cracking the verification code by traversing a static font library.

[0031] In addition, in order to further improve the resistance of the verification code, the scheme also proposes to apply special transformation processing to the string in the reference picture, which is easy to induce the multi-modal large model to produce recognition illusion (i.e. the multi-modal large model generates content that is inconsistent with the facts, fictitious or logically contradictory when generating content), and generates the string in the target picture in this way. This can significantly enhance the ability of the verification code to resist multi-modal large model attacks, and thus improve the reliability of the verification code.

[0032] In summary, the scheme is to use the illusion of the multi-modal large model to induce it to make mistakes, so that it cannot break through the verification code, which can significantly improve the defense capability of the verification code and greatly increase the difficulty of cracking by black and gray production, effectively resisting automated attacks.

[0033] Figure 1 A schematic diagram of an implementation scenario of an embodiment disclosed in the specification. Figure 1 In the multi-modal large model, the target string can be input into the large model to generate a reference picture containing the target string. In addition, the transformed string obtained by transforming the target string can also be input into the large model to obtain an error picture containing the transformed string. The transformation processing here is used to induce the multi-modal large model to produce recognition illusion, which can include but is not limited to deleting repeated characters, adding the same characters or multiple transformations, etc. Then, based on the preset target question, the reference picture and multiple target pictures including the above error picture, the verification code can be generated.

[0034] Figure 2 A flowchart of a method for generating a verification code according to an embodiment of the specification is shown. The method can be executed by any device, equipment, platform, device cluster with computing and processing capabilities. As shown in the figure, the method can include the following steps: Figure 2

[0035] Step S202, input the target string into the large model to generate a reference picture containing the target string for the preset target question.

[0036] In one example, the above target string has one or more of the following characteristics: contains repeated characters, has a plural form, and is an incorrect word.

[0037] For example, the above target string can be "LLAMA", which contains repeated characters "L" and has a plural form "LLAMAS". For another example, the above target string can be "LLMAS", which is an incorrect word.

[0038] ​The large model can include, but is not limited to, a FLUX.1-dev model (a model capable of accurately generating English characters and symbols), a Stable Diffusion 3 series, and the like.

[0039] Taking the FLUX.1-dev model as an example, a prompt word prompt1 can be input into the large model to output a reference picture containing a target string. The prompt word prompt1 includes the theme and scene of the picture, the text content (i.e., the target string), and the text style and position (such as font, color, size, and position, etc.).

[0040] In addition, in practice, the prompt word prompt1 can include more or less content, which is not limited in this specification.

[0041] The above target question is at least used to prompt the user to select a matching picture containing a string matching the target string in each target picture.

[0042] In one example, the above matching can be understood as the string contained in the matching picture being the same as the literal characters and their order in the target string. Here, the literal characters refer to non-special characters, including English characters and numbers, etc.

[0043] In addition, the above target question can also indicate the text color and position, etc. At this time, the prompt word prompt1 can be set according to the indication of the target question. For example, the text style and position in the prompt word prompt1 can be set according to the text color or position indicated in the target question.

[0044] Of course, in the case where the above target question does not indicate the theme and scene of the reference picture, the text content, and the text style and position, the content of the prompt word prompt1 can also be customized.

[0045] Finally, the present scheme can also set the above target question according to the risk level of the user.

[0046] Specifically, when the risk level of the user is high, some restriction conditions can be added to the target question, i.e., to set a complex target question. For example, the above target question is also used to prompt the user to select a matching picture whose string and target string have the same color or scene features.

[0047] When the risk level of the user is low, a simple target question can be set. For example, the above target text is also used to prompt the number of matching pictures.

[0048] It should be noted that since the OCR technology cannot recognize elements with semantics such as color or scene, the target question can effectively resist the combined attack of the OCR technology + the multi-modal large model when the target question prompts the color or scene of the text.

[0049] In step S204, the target string is transformed to obtain a transformed string (also referred to as a first string).

[0050] The above transformation processing is used to induce the multi-modal large model to produce an identification illusion. In one example, the transformation processing can include any of the following: deleting duplicate characters, adding identical characters, plural transformation, etc.

[0051] Taking the target string “LLAMA” as an example, the corresponding transformed string can be “LAMA”, that is, the duplicate character “L” is deleted; the corresponding transformed string can also be “LLAMMA”, that is, the same character “M” is added; and the corresponding transformed string can also be “LLAMAS” or “LLAMAs”, that is, plural transformation is performed.

[0052] In addition, in the case where the above target string is an error word, the above transformation processing can also mean editing the error word into a correct word. For example, in the case where the target string is “LLMAS”, the corresponding transformed string can be “LLAMAS”.

[0053] It should be noted that most multi-modal large models are constructed based on large language models, and the large language models have a bias towards correct words, that is, they tend to interpret a word as a correct word. Therefore, when the error word is included in the reference picture and the corresponding correct word is included in the error picture (i.e., the picture other than the matching picture in each target picture), it will have a certain interference effect on the multi-modal large model.

[0054] In step S206, the transformed string is input into the large model to generate an error picture (i.e., a first picture) containing the transformed string for the target question.

[0055] The large model here can include but is not limited to FLUX.1-dev model, Stable Diffusion 3 series, etc.

[0056] Taking the FLUX.1-dev model as an example, a prompt word prompt2 can be input into the large model to output an error picture containing the transformed string, and the prompt word prompt2 includes the theme and scene of the picture, the text content (i.e., the transformed string), and the text style and position (such as font, color, size, and position, etc.).

[0057] Similarly, the prompt word prompt2 can be set according to the indication of the target question.

[0058] In addition, in practice, more or less content can be included in the prompt word prompt2, which is not limited in this specification.

[0059] Experiments have proved that for the target string and the transformed string obtained by the above transformation processing on the target string, the multimodal large model will have hallucination, that is, the target string and the transformed string are regarded as the same string. Therefore, the error picture generated by the present scheme can resist the attack of the multimodal large model.

[0060] It should be noted that the present scheme can generate a plurality of error pictures corresponding to a plurality of transformed strings obtained by different transformation processing on the target string. Then, the plurality of error pictures can be classified into each target picture.

[0061] In a more specific example, the number of the plurality of error pictures can be 3.

[0062] Step S208, based on the above target question, reference picture and each target picture, generate a verification code.

[0063] Among them, each target picture here includes the plurality of error pictures described above. In addition, it can also include a plurality of correct pictures (i.e. the matching picture, also called the second picture) containing the target string itself. The difference between the correct picture and the reference picture is only that the font or color is different.

[0064] Of course, in order to resist the attack of the multimodal large model, a single correct picture can also be generated by the following steps:

[0065] Perform interference processing on the above target string to obtain a perturbed string. In one example, the interference processing includes any of the following: adding spaces, adding line breaks, adding hyphens, adding underscores, etc.

[0066] Input the perturbed string into the large model to generate a correct picture containing the perturbed string.

[0067] Still taking the target string "LLAMA" as an example, the corresponding perturbed string can be "LL-AMA", that is, a hyphen "-" is added; the corresponding perturbed string can also be "LL_AMA", that is, an underscore "_" is added; and the corresponding perturbed string can also be "LL AMA", that is, a space is added.

[0068] Experiments show that for the correct picture containing the perturbed string described above, the user can determine that the perturbed string and the target string are matched, so as to select the correct picture as the matching picture. However, the multimodal large model may determine that the perturbed string and the target string are not matched because the hyphen and the like are added in the perturbed string, so as to fail to select the correct picture as the matching picture.

[0069] After obtaining each target picture, the target pictures can be spliced randomly to obtain a spliced picture. Then, the reference picture is spliced on the outside of the spliced picture to obtain a final picture. Finally, the verification code is generated based on the target question and the final picture.

[0070] Figure 3 A schematic diagram of a verification code is shown in one example of the present specification. Figure 3 In this example, 9 target pictures form a 9x9 grid (i.e., a spliced picture), and the 9 target pictures include 6 incorrect pictures and 3 correct pictures. In addition, the reference picture is located above the spliced picture, and the target string contained therein is “LLAMA”. In the order from left to right and from top to bottom, the 3 correct pictures (i.e., matching pictures) are located at the 2nd, 7th and 9th positions, respectively. Finally, the target question in the verification code is “Find the 3 pictures that match the string contained in the topmost picture”. Here, the matching refers to the same literal characters and their order.

[0071] Figure 4 A schematic diagram of a method for generating a verification code is shown in one example of the present specification. Figure 4 In this example, a target string is first obtained, which can be an incorrect word. Then, the following three aspects of processing are performed in parallel for the target string: first, the target string is input into the large model to generate a reference picture containing the target string; second, the target string is subjected to transformation processing such as deleting duplicate characters, adding the same characters, and plural transformation, to obtain a plurality of transformed strings. The plurality of transformed strings are input into the large model to generate a plurality of incorrect pictures containing the plurality of transformed strings, respectively. Third, the target string is subjected to interference processing such as adding spaces, adding line breaks, adding hyphens, or adding underscores, to obtain a plurality of perturbed strings. The plurality of perturbed strings are input into the large model to generate a plurality of correct pictures containing the plurality of perturbed strings, respectively. Finally, a verification code is generated based on the preset target question, the reference picture, the plurality of incorrect pictures, and the plurality of correct pictures.

[0072] It should be understood that Figure 4 This is only an example, and in practice, the generation strategy of the verification code can be adjusted according to the risk level of the user. For example, when the risk level of the user is high, the following generation strategy can be adopted Figure 4The method shown is used to generate the verification code. When the risk level of the user is low risk, the second processing and the third processing described above can be selectively used. Specifically, when the second processing is used to generate the error picture, the plurality of correct pictures contain the target string itself, only the color or font is different. When the third processing is used to generate the correct picture, the plurality of error pictures can contain a string completely different from the target string. In addition, when the risk level of the user is high risk, the target question can also add some restrictions; and when the risk level of the user is low risk, the target question can also prompt the number of matching pictures.

[0073] In summary, the method for generating a verification code provided by the embodiments of the present specification uses the text-to-image capability of a large model to generate a reference picture and each target picture, without the need to maintain a font library or add new fonts, which can effectively reduce the generation cost of the verification code. In addition, the present solution applies special transformation or perturbation processing to the string in the reference picture, which easily induces the multi-modal large model to produce recognition hallucinations, and generates strings in the error picture or the correct picture, which can significantly enhance the ability of the verification code to resist multi-modal large model attacks, thereby improving the reliability of the verification code. Finally, the verification code generated by the present solution is friendly to users (i.e., low recognition difficulty), and there is no behavior that can hide relevant text, and only needs the user to screen each picture.

[0074] Corresponding to the above method for generating a verification code, one embodiment of the present specification also provides a device for generating a verification code, as shown in Figure 5 The device can include:

[0075] The input unit 502 is configured to input a target string into a large model to generate a reference picture containing the target string for a preset target question, the target question being used to prompt the user to select, in each target picture, a matching picture containing a string matching the target string.

[0076] The transformation unit 504 is configured to transform the target string to obtain a first string, the transformation including any of the following: deleting duplicate characters, adding the same characters, and plural transformation.

[0077] The input unit 502 is further configured to input the first string into the large model to generate a first picture containing the first string for the target question, and the first picture is classified into each target picture.

[0078] The generation unit 506 is configured to generate a verification code based on the target question, the reference picture, and each target picture.

[0079] In one embodiment, each target picture further includes a second picture for the target question, and the device further includes:

[0080] Interference unit 508 is used to interfere with the target string to obtain a second string, wherein the interference processing includes any one of the following: adding spaces, adding newline characters, adding hyphens, or adding underscores;

[0081] The input unit 502 is also used to input the second string into the large model, causing it to generate a second image containing the second string.

[0082] In one embodiment, the target string is an incorrect word, and the first string is the correct word corresponding to the incorrect word.

[0083] In one embodiment, the user is a high-risk user, and the target question is also used to prompt that the string in the matching image must have the same color or scene characteristics as the target string.

[0084] In one embodiment, the user is a low-risk user, and the target question is also used to indicate the number of matching images.

[0085] In one embodiment, the generating unit 506 includes:

[0086] The stitching submodule 5062 is used to randomly stitch together various target images to obtain a stitched image;

[0087] The stitching submodule 5062 is also used to stitch a reference image to the outside of the stitched image to obtain the final image;

[0088] The generation submodule 5064 is used to generate a CAPTCHA based on the target question and the final image.

[0089] In one embodiment, the above-mentioned large model is the FLUX.1 model.

[0090] The functions of each functional unit of the apparatus in the above embodiments of this specification can be implemented through the steps of the above method embodiments. Therefore, the specific working process of the apparatus provided in one embodiment of this specification will not be repeated here.

[0091] The apparatus for generating verification codes provided in one embodiment of this specification is capable of generating highly reliable verification codes at a low cost.

[0092] According to another embodiment, a computer-readable storage medium is also provided, on which a computer program is stored, which, when executed in a computer, causes the computer to perform a combination Figure 2 The method described.

[0093] According to another embodiment, a computing device is also provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, it implements a combination... Figure 2 The method described.

[0094] Each of the various embodiments described in this specification are described in the context of a progression of embodiments. The various embodiments described can be combined, reformulated, substituted, deleted, enhanced, and / or modified in whole or in part into other embodiments, all of which fall within the scope of the disclosure. Furthermore, many of the embodiments described herein are described in the context of method embodiments. Embodiments of a medium or device can be substantially similar to the corresponding method embodiments, but are not described in detail in order to avoid unnecessarily obscuring the present disclosure.

[0095] The steps of a method or algorithm described in connection with the present disclosure can be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module can reside in RAM memory, flash memory, ROM memory, EPROM memory, EEPROM memory, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor such that the processor can read information from, and write information to, the storage medium. In the alternative, the storage medium can be integral to the processor. The processor and the storage medium can reside in an ASIC. Alternatively, the processor and the storage medium can be located in a server, and the server can be located in a cloud. The processor and the storage medium can comprise one or more components of the example devices described herein. The processor can execute software modules stored in a storage medium or according to instructions received from a software module stored in a storage medium.

[0096] Those skilled in the art will appreciate that the functions described in the one or more examples described above can be implemented in hardware, software, firmware, or any combination thereof. If implemented in software, the functions can be stored on or transmitted over as one or more instructions or code on a computer-readable medium. Computer-readable media include both computer storage media and communication media including any medium that facilitates transfer of a computer program from one place to another. Storage media can be any available media that can be accessed by a general purpose or special purpose computer.

[0097] The above description of specific embodiments of the disclosure has been presented for the purpose of illustration. Other embodiments are within the scope of the following claims. In some cases, the actions recited in the claims can be performed in a different order and still achieve desirable results. In addition, the process depicted in the accompanying figures does not necessarily require the particular order shown, or sequential order to achieve the desired results. In certain implementations, multitasking and parallel processing can be advantageous.

[0098] The above detailed description of the specific implementation is further detailed for the purpose of the specification, technical solutions and beneficial effects, and it should be understood that the above detailed description is only the specific implementation of the specification and is not used to limit the protection scope of the specification, and any modification, equivalent replacement, improvement, etc. made on the basis of the technical solutions of the specification shall be included in the protection scope of the specification.

Claims

1. A method for generating a verification code, comprising: inputting a target string into a large model to generate a reference picture containing the target string for a preset target question; the target question is used at least to prompt a user to select a matching picture containing a string matching the target string in each target picture; performing transformation processing on the target string to obtain a first string; the transformation processing includes any one of the following: deleting duplicate characters, adding identical characters, and plural transformation; inputting the first string into the large model to generate a first picture containing the first string for the target question; classifying the first picture into the target pictures; generating a verification code based on the target question, the reference picture, and the target pictures.

2. The method of claim 1, wherein, the target pictures further include a second picture for the target question; the second picture is obtained by: performing interference processing on the target string to obtain a second string; the interference processing includes any one of the following: adding spaces, adding line breaks, adding hyphens, and adding underscores; inputting the second string into the large model to generate the second picture containing the second string.

3. The method of claim 1, wherein, the target string is an error word, and the first string is a correct word corresponding to the error word.

4. The method of claim 1, wherein, the target user is a high-risk user; the target question is further used to prompt that the color or scene feature of the string and the target string needs to be the same.

5. The method of claim 1, wherein, the user is a low-risk user; the target question is further used to prompt the number of matching pictures.

6. The method of claim 1, wherein, the generating of the verification code includes: randomly splicing the target pictures to obtain a spliced picture; splicing the reference picture on the outside of the spliced picture to obtain a final picture; generating a verification code based on the target question and the final picture.

7. The method of claim 1, wherein, the large model is a FLUX.1 model.

8. An apparatus for generating a verification code, comprising: an input unit configured to input a target string into a large model to generate a reference picture containing the target string for a preset target question; the target question is used at least to prompt a user to select a matching picture containing a string matching the target string in each target picture; a transformation unit configured to perform transformation processing on the target string to obtain a first string; the transformation processing includes any one of the following: deleting duplicate characters, adding identical characters, and plural transformation; the input unit is further configured to input the first string into the large model to generate a first picture containing the first string for the target question; and classify the first picture into the target pictures; a generation unit configured to generate a verification code based on the target question, the reference picture, and the target pictures.

9. A computer readable storage medium having stored thereon a computer program, wherein, when the computer program is executed in the computer, the computer is caused to execute the method of any one of claims 1-7.

10. A computing device comprising a memory and a processor, wherein, the memory stores executable code, and the processor executes the executable code to implement the method of any one of claims 1-7.