Sliding block verification code generation method, system and device and medium

By generating irregularly shaped slider CAPTCHAs and combining them with similar interfering shapes, the problem of existing slider CAPTCHAs being easily cracked is solved, improving anti-cracking capabilities and defense effects, and adapting to various attack methods.

CN121837422APending Publication Date: 2026-04-10SUZHOU CHUANGLUTIANXIA 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-11-29
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

Existing slider CAPTCHAs are easily cracked, have low defense against machine attacks, lack complex dynamic feature constraints, and the distinguishing features between interfering sliders and valid sliders are not significant.

Method used

The system generates irregularly shaped foreground objects and background images using a preset model. It forms irregular gaps by randomly generating quadrilateral intersections and combining similar interference shapes. This eliminates the fixed pattern of setting gaps in the background image and enhances its anti-hacking capabilities.

Benefits of technology

Significantly improves the anti-cracking capability of slider CAPTCHAs, prevents machines from locating vulnerabilities through template matching, balances user experience and security, and adapts to constantly changing attack methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121837422A_ABST
    Figure CN121837422A_ABST
Patent Text Reader

Abstract

The invention discloses a sliding block verification code generation method and system, a medium and equipment, and relates to the field of Internet information security. The method comprises the steps of generating a foreground image and a background image; acquiring a mask of the foreground object, randomly selecting one edge of the mask, randomly sampling two points in a preset effective area in the foreground object, and combining two end points of the selected edge to form a quadrangle; calculating the intersection of the quadrangle and the mask, namely the irregular shape of the foreground object; selecting another object of the same category as the foreground object, and generating an interference irregular shape; and fusing the foreground object with the irregular shape removed with the background image to obtain a basic image of the sliding block verification code, and obtaining a first sliding block component and a second sliding block component based on the irregular shape and the interference irregular shape. According to the application, a double-slider component is formed through an irregular gap of a foreground object and a similar interference shape, so that a machine is prevented from matching and positioning the gap through a template, and the anti-cracking capability of the slider verification code is greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of Internet information security, in particular to a method, system, device and medium for generating a sliding block verification code. BACKGROUND

[0002] With the continuous development of Internet technology, the demand for identity verification and machine attack prevention in the field of Internet information security is increasingly prominent, and various image verification codes have emerged as the times require, including sliding block verification code, text point selection verification code, sequence point selection verification code, icon point selection verification code, sliding puzzle verification code, etc. Among them, the sliding block verification code has become one of the most widely used verification code types in current Internet scenarios due to its simple operation process and good user interaction experience, and is widely adapted to various business scenarios that need to implement identity verification or prevent machine automation operation, such as login, registration, payment verification, data submission, etc.

[0003] The implementation process of the existing conventional sliding block verification code includes: constructing a background image containing a specific gap structure, which is used as the core display carrier of the verification code; in the verification link, the above background image containing the gap and the draggable sliding block element are presented to the user, the user manually drags the sliding block to the corresponding position of the gap in the background image, so that the sliding block and the gap are matched in shape and position, and if the matching result meets the preset standard, the verification is determined to be passed. The implementation process of other forms of sliding block verification code includes: on the basis of the conventional sliding block verification code, an interference sliding block is added, that is, an interference sliding block similar in shape to the effective sliding block is additionally generated, and the interference sliding block, the effective sliding block and the background image containing the gap are displayed together, and the user needs to identify the effective sliding block that can match the gap from the multiple sliding block elements and complete the dragging operation to complete the verification process.

[0004] However, the conventional sliding block verification code in the prior art adopts a fixed design mode of setting a gap in the background image, and an attacker can extract and locate the gap features in the background image through template matching technology, thereby quickly obtaining the gap position information. At the same time, the sliding track parameter design of this type of verification code is simple and lacks complex dynamic feature constraints, which is easy to be attacked by a machine program by simulating the sliding path of a regular user to generate an operation track that meets the verification requirements, resulting in a low defense coefficient against machine attacks. Moreover, the distinguishing features of the interference sliding block and the effective sliding block are not significant, and the matching logic of the gap and the sliding block is not optimized, which cannot effectively confuse the attacker's identification of the effective verification element. SUMMARY

[0005] The present application provides a method, system, device and medium for generating a sliding block verification code to solve the problem that the existing sliding block verification code is easy to be cracked.

[0006] In a first aspect, the present application provides a method for generating a sliding block verification code, the method comprising: generate the foreground image and the background image by using a preset model; obtain a mask of the foreground object from the foreground image, randomly select an edge of the mask, and randomly sample two points in a preset effective region inside the foreground object to form a quadrilateral in combination with two end points of the selected edge; calculate an intersection of the quadrilateral and the mask, and a pixel region corresponding to the intersection is an irregular shape of the foreground object; select another object of the same category as the foreground object, and generate an interference irregular shape by using the above method of generating the irregular shape; fuse the foreground object after removing the irregular shape with the background image to obtain a basic image of the sliding block verification code, and obtain a first sliding block component and a second sliding block component based on the irregular shape and the interference irregular shape respectively.

[0007] By using the above technical solution, the fixed mode of the background image with a notch is abandoned, the double sliding block components are formed by the irregular notch of the foreground object and the interference shape of the same category, the notch is avoided to be positioned by the machine through template matching, and the anti-cracking capability of the sliding block verification code is greatly improved.

[0008] In a specific implementable scheme, the foreground object is a common object, and the categories of the common object include fruits, vegetables, animals, plants, food, daily necessities, and the like. After the foreground image is generated, the foreground image is classified and saved according to the categories of the common object, and the saved foreground image is manually screened to retain the foreground image in which the foreground object is clear and meets the requirements of visual identification of the verification code.

[0009] By using the above technical solution, it is ensured that the foreground object is clear and meets the requirements of visual identification, which not only improves the user verification experience, but also provides high-quality basic materials for subsequent generation of irregular notches, and guarantees the stability of the verification code function.

[0010] In a specific implementable scheme, when the background image is generated, the prompt words of the preset model used include geometric patterns.

[0011] By using the above technical solution, the background image carries the geometric patterns to enhance the interference, which interferes with the recognition of the machine on the foreground object and the notch, while not affecting the visual judgment of the user, and balances the safety and user experience.

[0012] In a specific implementable scheme, the process of obtaining the mask of the foreground object from the foreground image includes: perform binaryzation processing on an Alpha channel of the foreground image to obtain the mask of the foreground object; determine a minimum circumscribed rectangle of the foreground object, crop the foreground object according to four vertices of the minimum circumscribed rectangle, and scale the cropped foreground object according to a preset ratio, so that a long side of the scaled foreground object is a preset pixel value.

[0013] By adopting the technical scheme, the foreground object mask is accurately extracted and its size is regulated, invalid background region interference is reduced, the accuracy and consistency of subsequent quadrilateral construction and gap generation are ensured, and the verification code generation efficiency is improved.

[0014] In a specific implementable scheme, the method of sampling in the preset effective region inside the foreground object includes: The first region and the second region in the width direction of the foreground object are sampled respectively, and the intersection of the quadrilaterals formed after sampling and the mask accounts for a proportion of the total pixels of the mask corresponding to the foreground object within a preset threshold range.

[0015] By adopting the technical scheme, the pixel proportion of the gap to the foreground object is controlled within a reasonable range, which ensures that the gap can be clearly identified by the user, and avoids that the gap is too large or too small, causing the machine to be easily cracked or the user to be difficult to operate.

[0016] In a specific implementable scheme, the method further includes: The contour points of the irregular shape and the interference irregular shape are extracted, the contour points are subjected to a line drawing process, the line drawing color is set to a preset color, and the irregular shape and the interference irregular shape after line drawing are respectively placed at the center position of a blank image of a preset size.

[0017] By adopting the technical scheme, the visual features of the interference irregular shape are strengthened, so that it is clearly presented in the slider component, which not only enhances the interference effect on the machine, but also does not confuse the foreground object, ensuring that the user can accurately distinguish the verification elements.

[0018] In a specific implementable scheme, the method further includes: The update trigger condition is set, and the update trigger condition includes a preset time period or a cumulative user access threshold; When the update condition is triggered, the foreground object different from the original category or different in form of the same category, the background image with a differentiated geometric pattern, and the irregular shape and the interference irregular shape generated based on the updated foreground object are generated.

[0019] By adopting the technical scheme, the dynamic update of the core elements of the verification code is realized, the attacker is prevented from cracking by obtaining fixed elements through a library, the long-term defense effectiveness of the slider verification code is ensured, and the continuously changing attack means is adapted.

[0020] In a second aspect of the present application, a generation system of a slider verification code is provided, and the system includes: The image generation module is configured to generate a foreground image and a background image, wherein the foreground object is limited to a common object by a prompt word when the foreground image is generated, and the background contains a geometric pattern by a prompt word when the background image is generated; The interference shape module is configured to select another object of the same category as the foreground object, generate an interference irregular shape according to the working logic of the gap generation module, extract contour points of the interference irregular shape for stroke processing, and place the interference irregular shape after stroke processing in the center of a blank image of a preset size. The image fusion and slider component module is configured to fuse the foreground object after the irregular shape is removed with the background image to obtain a basic image of the slider verification code, and generate a first slider component and a second slider component based on the irregular shape and the interference irregular shape, respectively.

[0021] In a third aspect of the present application, an electronic device is provided, comprising a processor and a memory; wherein the memory stores a computer program, and the computer program is adapted to be loaded by the processor and execute the method steps described above.

[0022] In a fourth aspect of the present application, a computer storage medium is provided, which stores a plurality of instructions, and the instructions are adapted to be loaded by a processor and execute the method steps described above.

[0023] In summary, the one or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages: The present application does not set a fixed gap on the background image, but generates an irregular gap on the foreground object, and makes an interference shape based on the foreground object of the same category, thereby fundamentally preventing the machine from finding the gap position through template matching, and greatly improving the cracking difficulty. BRIEF DESCRIPTION OF DRAWINGS

[0024] Figure 1 is a flowchart of a generation method of a slider verification code provided in the embodiments of the present application; Figure 2 is a schematic diagram of a foreground image and a foreground object mask provided in the embodiments of the present application; Figure 3 is a schematic diagram of a quadrilateral provided in the embodiments of the present application; Figure 4 is a schematic diagram of an irregular shape provided in the embodiments of the present application; Figure 5 is a schematic diagram of a foreground object after the irregular shape is removed provided in the embodiments of the present application; Figure 6 is a schematic diagram of an interference irregular shape provided in the embodiments of the present application; Figure 7 is a schematic diagram of a foreground object after the background image is fused provided in the embodiments of the present application; Figure 8 is a schematic diagram of a slider verification code and a slider component provided in the embodiments of the present application.

[0025] 10, first slider component; 20, second slider component. DETAILED DESCRIPTION

[0026] In order to make the technical solution in the specification better understood by the skilled in the art, the technical solution in the specification will be clearly and completely described below in combination with the drawings in the specification. Obviously, the described embodiments are only some of the embodiments of the present application, not all the embodiments.

[0027] In the description of the embodiments of the present application, the words such as "for example" or "for instance" are used to represent an example, illustration or description. Any embodiment or design scheme described as "for example" or "for instance" in the embodiments of the present application should not be interpreted as more preferred or more advantageous than other embodiments or design schemes. In fact, the words such as "for example" or "for instance" are intended to present the relevant concept in a specific way.

[0028] In the description of the embodiments of the present application, the term "a plurality of" means two or more. For example, a plurality of systems means two or more systems, and a plurality of screen terminals means two or more screen terminals. In addition, the terms "first" and "second" are only used for description purposes, and should not be understood as indicating or implying relative importance or implicitly indicating the indicated technical features. Therefore, the features defined with "first" and "second" can explicitly or implicitly include one or more of the features. The terms "include", "contain", "have" and their variants mean "include but are not limited to", unless otherwise specifically emphasized.

[0029] Please refer to Figure 1 , a flowchart of a method for generating a slider verification code is specifically disclosed. The method can be implemented by a computer program, a single-chip microcomputer or a slider verification code generation system. The computer program can be integrated in a computer device or run as an independent tool application. Specifically, the method comprises S100 to S500, and the steps are as follows: S100, generating foreground and background images by using a preset model; In some embodiments, the foreground image and the background image are respectively generated by using preset models. The preset model for generating the foreground image is a Stable Diffusion Layer in the text-to-image model, which outputs images in RGBA format and is used to generate foreground object images. The preset model for generating the background image is a Stable Diffusion in the text-to-image model, which outputs images in RGB format and is used to generate background images. Both of them can generate corresponding images meeting the requirements of the sliding block verification code according to the input prompt.

[0030] In some embodiments, the foreground image is in RGBA (Red Green Blue Alpha) format, which includes three color channels of red, green and blue and an Alpha transparency channel. The Alpha channel is used to control the transparency of the image background. The core content of the foreground image is the foreground object, which refers to an entity object that can be clearly recognized by the user and is used to generate irregular shapes subsequently. The background image is in RGB (Red Green Blue) format, which includes only three color channels of red, green and blue without a transparency channel. The background image provides a display carrier for the foreground object and enhances the interference for machine recognition through specific design.

[0031] In some embodiments, when generating the foreground image, the prompt input to the preset model for generating the foreground image directly specifies a specific object category, such as "apple" and the like. The model directly outputs an RGBA format image containing the corresponding specific category object and is used to generate foreground object images.

[0032] In some embodiments, during the generation process, a preset number of RGBA images of each specific object category are generated and saved in a directory named after the specific category. For example, RGBA images containing apples are saved in the "apple" directory. The preset number can be 100, 200, 300, etc.

[0033] After generation, the images in each specific category directory are manually screened: confirm that the objects in the images in the directory are normal objects of the corresponding category, for example, the "apple" directory contains only normal apple images without other category objects or deformed objects; verify that the Alpha channel of the image is consistent with the visual presentation to ensure that the object outline is clear in vision and the rest of the area is transparent except the area where the object itself is located.

[0034] When generating the background image, the prompt word input to the preset model for generating the background image needs to meet the subsequent interference requirements, for example, containing geometric pattern related content.

[0035] Regardless of the foreground image or the background image, after being generated, preliminary verification needs to be performed, and the verification content includes whether the image format is correct and whether the image is damaged. If the image meets the requirements, it enters the subsequent step; if it does not meet the requirements, the prompt word is adjusted and the corresponding preset model is called to generate the image.

[0036] On the basis of the above embodiment, as another optional embodiment, the foreground object is a common object, and the categories of the common object include fruits, vegetables, animals, plants, food, daily necessities, and other common objects in life. Further, after completing the classification and saving, the saved foreground image is manually screened. The manual screening standard can include two aspects: first, the foreground object is clear, that is, the edge of the foreground object is not blurred, and the details are not missing; second, it meets the visual recognition requirements of the verification code, that is, the foreground object occupies a moderate proportion in the foreground image, neither too large to exceed the image boundary, nor too small to make it difficult for the user to observe, for example, the proportion of the foreground object in the foreground image is controlled between 50% and 70%. The screening personnel will view the foreground images in each storage directory one by one, delete the foreground images that do not meet the above standard from the storage directory, and retain the foreground images that meet the standard for the subsequent generation process of the sliding block verification code.

[0037] On the basis of the above embodiment, as another optional embodiment, when generating the background image, the prompt word of the preset model used includes a geometric pattern.

[0038] In some embodiments, the generation process of the background image is optimized. Specifically, by adding geometric pattern related content to the prompt word of the preset model, the interference of the background image to machine recognition is enhanced, while ensuring that the identification of the foreground object by the user is not affected.

[0039] First, the specific type of geometric pattern is determined. The geometric pattern can be selected from a circular array, a triangular grid, a square interlaced pattern, a diamond arrangement, etc. These geometric patterns need to have a certain degree of complexity to avoid insufficient interference effect due to too simple patterns.

[0040] Further, the content containing the geometric pattern is integrated into the prompt word of the preset model. The above prompt word is input into the preset model through a preset interface, and the format of the background image is set as an RGB format and the size parameter of the background image. After the preset model generates the corresponding background image according to the input prompt word, the generated background image is checked, and the checking content includes whether the geometric pattern is generated according to the requirement of the prompt word, whether the color of the geometric pattern is adapted to the foreground object, and whether the geometric pattern is too dense to affect the recognition of the foreground object. If the background image meets the requirement, it is used for subsequent fusion with the foreground object; if it does not meet the requirement, for example, the geometric pattern is missing or the color deviation is too large, the prompt word is adjusted again and the preset model is called to generate the background image.

[0041] S200, obtaining a mask of the foreground object from the foreground image, randomly selecting an edge of the mask, and randomly sampling two points in a preset effective area inside the foreground object to form a quadrilateral in combination with two end points of the selected edge; Reference Figure 2 In the embodiments of the present application, the mask refers to a binary image used for marking the specific area of the foreground object in the foreground image, which only contains two pixel values of black and white. The white pixel area corresponds to the area of the foreground object, and the black pixel area corresponds to the transparent background area of the foreground image.

[0042] Reference Figure 3 In some embodiments, after obtaining the mask, an edge of the mask is randomly selected. The edges of the mask include the upper edge, the lower edge, the left edge and the right edge. A random number generation algorithm is used to select one of the four edges as the target edge. For example, a random integer from 1 to 4 is generated, 1 corresponds to the upper edge, 2 corresponds to the lower edge, 3 corresponds to the left edge, and 4 corresponds to the right edge.

[0043] Further, two points are randomly sampled in a preset effective area inside the foreground object. The preset effective area refers to an area inside the foreground object that can ensure that the irregular shape generated subsequently meets the requirements. This area needs to avoid being too close to the edge of the foreground object to prevent the generated notch from exceeding the range of the foreground object or being too small in size. The range of the preset effective area is determined by image coordinate positioning, for example, the preset effective area is limited to an area of 20% to 80% in the width direction and 20% to 50% in the height direction of the foreground object, to ensure that the sampling points are located in the core area of the foreground object.

[0044] Further, the two end points of the randomly selected edge of the mask and the two randomly sampled points are used as vertices to form a quadrilateral. For example, if the selected edge of the mask is the upper edge, the two end point coordinates of the upper edge are (0, 0) and (w-1, 0) respectively, where w is the width pixel value of the mask; the two point coordinates sampled in the preset effective area include: [int(w * (random.randint(6, 8) / 10)), int(h * (random.randint(2, 4) / 10))], [int(w * (random.randint(2, 4) / 10)), int(h * (random.randint(2, 4) / 10))].

[0045] On the basis of the above-mentioned embodiments, as another optional embodiment, the process of obtaining the mask of the foreground object from the foreground image comprises: S201, performing binaryzation processing on the Alpha channel of the foreground image to obtain the mask of the foreground object. In some embodiments, the Alpha channel of the foreground image is used to represent the transparency of each pixel in the image, and the value range of the Alpha channel is 0 to 255, wherein the Alpha value of 255 represents that the pixel is completely opaque, corresponding to the pixel of the foreground object; the Alpha value of 0 represents that the pixel is completely transparent, corresponding to the background pixel of the foreground image. The Alpha value of each pixel in the foreground image is extracted by an image processing algorithm to form an Alpha channel data matrix.

[0046] Further, an Alpha threshold value is set, which is used to distinguish the foreground object pixel and the background pixel, and the specific value of the Alpha threshold value is determined according to the transparency distribution of the foreground image to ensure that the foreground object and the background can be accurately separated.

[0047] The Alpha channel data is subjected to binaryzation processing. Each Alpha value in the Alpha channel data matrix is traversed, if the Alpha value of a certain pixel is greater than the set Alpha threshold value, the color of the pixel in the mask is set to white, the pixel value of the white pixel is 255, and the region corresponding to the pixel is the region of the foreground object; if the Alpha value of a certain pixel is less than or equal to the set Alpha threshold value, the color of the pixel in the mask is set to black, the pixel value of the black pixel is 0, and the region corresponding to the pixel is the transparent background region of the foreground image.

[0048] After the above-mentioned binaryzation processing, a binary image with the same size as the foreground image is obtained, which is the mask of the foreground object.

[0049] In some embodiments, the Alpha threshold value is set to 128.

[0050] S202, determining the minimum circumscribed rectangle of the foreground object, cropping the foreground object according to the four vertices of the minimum circumscribed rectangle, and scaling the cropped foreground object according to a preset ratio, so that the long side of the scaled foreground object is a preset pixel value.

[0051] The minimum circumscribed rectangle in the embodiments of the present application refers to the minimum rectangle that can completely enclose the white pixel region in the mask, and the four sides of the rectangle are tangent to the leftmost, rightmost, uppermost and lowermost edges of the foreground object. All white pixels in the mask are traversed by an image recognition algorithm, and the horizontal and vertical coordinates of each white pixel are recorded. Then, the minimum horizontal coordinate value and the maximum horizontal coordinate value are selected from the horizontal coordinates of all white pixels, and the minimum vertical coordinate value and the maximum vertical coordinate value are selected from the vertical coordinates of all white pixels. A rectangle is constructed with the minimum horizontal coordinate value and the minimum vertical coordinate value as the top-left corner vertex coordinates, and the maximum horizontal coordinate value and the maximum vertical coordinate value as the bottom-right corner vertex coordinates. The rectangle is the minimum circumscribed rectangle of the foreground object. For example, the horizontal coordinate range of all white pixels in the mask is 20 to 180, and the vertical coordinate range is 30 to 170. The top-left corner vertex coordinates of the minimum circumscribed rectangle are (20, 30), and the bottom-right corner vertex coordinates are (180, 170).

[0052] Further, the foreground object is cropped according to the four vertices of the minimum circumscribed rectangle. The foreground object in the foreground image is cropped with the four vertices of the minimum circumscribed rectangle as the boundary. During the cropping process, only the part of the foreground object within the minimum circumscribed rectangle is retained, and the transparent background part outside the minimum circumscribed rectangle is removed, thereby reducing the data amount for subsequent processing and ensuring the integrity of the foreground object. For example, the vertex coordinates of the minimum circumscribed rectangle are (20, 30), (180, 30), (180, 170) and (20, 170). When the foreground image is cropped, only the region with horizontal coordinates between 20 and 180 and vertical coordinates between 30 and 170 is retained, which is the region containing the complete foreground object.

[0053] Further, the cropped foreground object is scaled by a preset ratio, so that the long side of the scaled foreground object is a preset pixel value. First, the width and height of the cropped foreground object are obtained, for example, the width of the cropped foreground object is 160 pixels and the height is 140 pixels, and the long side is 160 pixels at this time. A preset pixel value is set, which is adapted to the display scenario of the sliding block verification code to ensure that the user can clearly observe the foreground object and the gap, for example, the preset pixel value is set to 150 pixels. The scaling ratio is calculated, scaling ratio = preset pixel value / length of the long side of the cropped foreground object. The cropped foreground object is scaled by the scaling ratio, and the width and height of the scaled foreground object are adjusted by the scaling ratio. For example, the long side of the cropped foreground object is 160 pixels, the preset pixel value is 150 pixels, the scaling ratio is 0.9375, the width of the scaled foreground object is 150 pixels, and the height is 131.25 pixels, which is rounded to 131 pixels.

[0054] On the basis of the above embodiments, as another optional embodiment, the method of sampling in the preset effective area inside the foreground object includes: The first area and the second area in the width direction of the foreground object are respectively sampled, and the proportion of the pixels of the intersection of the quadrilateral formed after sampling and the mask to the total pixels of the mask corresponding to the foreground object is within a preset threshold range.

[0055] In some embodiments, the first area is set to a range of 20% to 40% in the width direction of the foreground object, and the second area is set to a range of 60% to 80% in the width direction of the foreground object.

[0056] In some embodiments, one point is respectively sampled in the first area and the second area, and the longitudinal coordinates of the two sampling points need to be within a reasonable range in the height direction of the foreground object, for example, between 20% and 40% of the height of the foreground object, to ensure that the sampling points are located inside the foreground object and are not close to the upper and lower edges of the foreground object, avoiding that the generated gap is too close to the edge to affect user identification.

[0057] Further, after the two sampling points and the two end points of the edge of the mask randomly selected in S200 form a quadrilateral, the intersection of the quadrilateral and the mask of the foreground object is calculated. By means of image pixel comparison, all pixels in the range of the quadrilateral are traversed to determine whether each pixel belongs to the white pixel area of the mask at the same time, and if it does, the pixel is marked as an intersection pixel; the number of all intersection pixels is counted, and the total number of white pixels in the mask (i.e. the total number of pixels of the foreground object) is counted at the same time; the ratio of the number of intersection pixels to the total number of pixels of the foreground object corresponding to the mask is calculated, which is the proportion of the pixels of the intersection of the quadrilateral and the mask to the total pixels of the foreground object corresponding to the mask.

[0058] Further, a preset threshold range is set, which needs to ensure that the size of the irregular shape is moderate, which can be clearly identified by the user and can effectively resist the identification cracking of the machine on the gap position, for example, the preset threshold range is set to 0.15 to 0.3. It is judged whether the proportion calculated above is within the preset threshold range, if it is within the range, the quadrilateral and the corresponding intersection area are retained for subsequent generation of irregular shapes; if it is not within the range, the sampling points in the first area and the second area are re-sampled, the quadrilateral is re-formed and the intersection ratio is calculated until the ratio meets the requirements of the preset threshold range.

[0059] S300, the intersection of the quadrilateral and the mask is calculated, and the pixel area corresponding to the intersection is the irregular shape of the foreground object; Reference Figure 4 and Figure 5Further, the intersection region obtained by the above calculation has a shape determined by the quadrilateral shape and the contour of the foreground object, and the boundary is not a regular circle, rectangle or other common shape. Therefore, the pixel region corresponding to the intersection is defined as an irregular shape of the foreground object. The irregular shape can avoid the machine identifying the gap position through a conventional shape matching algorithm, thereby improving the defense capability of the sliding block verification code. After determining the irregular shape, the pixel coordinate range of the gap is recorded for subsequent removal of the gap region in the foreground object and generation of the sliding block component.

[0060] S400, selecting another object of the same category as the foreground object, and generating an interference irregular shape according to the above method of generating an irregular shape; Reference Figure 6 In some embodiments, from the foreground images classified and saved in S101 and manually screened, another foreground image of the same category as the current foreground object is selected, and the foreground object in the foreground image is another object of the same category as the current foreground object. For example, if the current foreground object is an apple, which belongs to the apple category, another foreground image containing an apple is selected from the apple category foreground image directory. Selecting an object of the same category can ensure that the generated interference irregular shape has certain similarity in shape characteristics with the irregular shape of the current foreground object, thereby enhancing the interference effect on machine recognition.

[0061] According to the method of generating an irregular shape in S200 to S300, the interference irregular shape corresponding to the above another object is generated. After generating the interference irregular shape, the shape is verified. The verification content includes whether the size of the interference irregular shape is similar to the size of the irregular shape of the current foreground object and whether the shape has similarity. If the requirements are met, the interference irregular shape is used for subsequent construction of the sliding block component. If the requirements are not met, another object of the same category is selected and the interference irregular shape is generated according to the above method.

[0062] S401, on the basis of the above embodiments, as another optional embodiment, the method further comprises: The contour points of the irregular shape and the interference irregular shape are extracted, and the contour points are subjected to a stroke processing, the stroke color is set as a preset color, and the irregular shape and the interference irregular shape after the stroke processing are respectively placed at the center position of a blank image of a preset size.

[0063] In some embodiments, an edge detection algorithm is used to perform edge detection on the pixel region corresponding to the irregular shape and the interference irregular shape. By calculating the change rate of the pixel gray value, the pixel points at the edges of the irregular shape and the interference irregular shape are identified. The pixel points are contour points of the corresponding irregular shape or interference irregular shape. The coordinates of all contour points are recorded to form a contour point set.

[0064] Further, the extracted contour points are subjected to a stroke processing, and the stroke color is set to a preset color. The preset color needs to have a high visual contrast, so that the contour of the irregular shape of the interference can be clearly visible in the slider component, without being confused with the color of the foreground object. According to the recorded contour point set, a line drawing algorithm is used to draw a continuous line at the contour points of the irregular shape and the irregular shape of the interference, with the preset color as the line color. The width of the line can be set to a preset pixel width.

[0065] S500, the foreground object after removing the irregular shape is fused with the background image to obtain a base image of the slider verification code. The first slider component 10 and the second slider component 20 are obtained based on the irregular shape and the irregular shape of the interference, respectively.

[0066] Reference Figure 7 and Figure 8 In some embodiments, according to the pixel coordinate range of the irregular shape recorded in S300, the pixels in the pixel region corresponding to the foreground object within the coordinate range are marked as transparent pixels, thereby realizing the operation of removing the irregular shape, and obtaining the foreground object after removing the gap.

[0067] Further, the foreground object after removing the irregular shape is fused with the background image generated in S100 or S102. The placement position of the foreground object in the background image is determined, which needs to ensure that the user can clearly observe the foreground object and the gap, for example, the foreground object is placed in the horizontally centered and vertically offset position of the background image. The specific coordinates can be set to the region of 20% to 40% of the horizontal coordinate and 10% to 30% of the vertical coordinate of the background image. The foreground object after removing the gap is superimposed on the above-mentioned preset position of the background image through an image superimposition algorithm. The transparency property of the foreground object is maintained during the superimposition process. The region covered by the foreground object in the background image displays the pixels of the foreground object, and the region not covered displays the pixels of the background image. The fusion obtains a base image of the slider verification code.

[0068] Further, the first slider component 10 and the second slider component 20 are obtained based on the irregular shape in S300 and the processed irregular shape of the interference in S401, respectively. The irregular shape corresponds to the first slider component 10, which is used to correctly unlock the slider verification code. The irregular shape of the interference corresponds to the second slider component 20, which is used to interfere with attackers and cannot unlock the slider verification code. When the user drags the first slider component 10 or the second slider component 20, the verification system compares the morphological features of the irregular shape of the interference in the slider component with the irregular shape in the base image. If they match, the verification is passed; if they do not match, the verification fails.

[0069] On the basis of the above-mentioned embodiments, as another optional embodiment, the method further comprises: S501, set an update trigger condition, the update trigger condition including a preset time period or a cumulative user access amount threshold value; In some embodiments, the update trigger condition includes both the preset time period and the cumulative user access amount threshold value, and one of the trigger conditions or both of the trigger conditions can be selected according to an actual application scenario, and when any trigger condition is met, the update process of the sliding block verification code element is started.

[0070] For the preset time period, a fixed time interval is set, which needs to balance the security of the verification code and the consumption of system resources, for example, 24 hours, that is, the update operation is triggered once every 24 hours. A timing module is deployed in the electronic device, which starts timing from the time point of the last update completion, and calculates the interval between the current time and the last update time in real time, and when the interval reaches the preset time period, the update condition is triggered.

[0071] For the cumulative user access amount threshold value, a specific user access number value is set, for example, 1000 times, that is, when the server accumulatively receives 1000 times of user sliding block verification code access requests, the update operation is triggered once. An access amount statistical module is deployed in the electronic device, which statistically counts the number of verification code access requests sent by the user in real time, and the count is increased by 1 every time a valid request is received, and when the count reaches the preset cumulative user access amount threshold value, the update condition is triggered.

[0072] In some embodiments, the preset time period is set to 24 hours, and the cumulative user access amount threshold value is set to 1000 times; the timing module synchronizes the server time by using the network time protocol (NTP), to ensure the accuracy of timing; the access amount statistical module filters invalid access requests (such as repeated requests, malicious requests), and only counts the access requests of valid users.

[0073] S502, when the update condition is triggered, a foreground object different from the original category or different from the same category in a different form, a background image with a differentiated geometric pattern, and an irregular shape generated based on the updated foreground object and an interference irregular shape are generated.

[0074] When the update trigger condition in S501 is triggered, a new sliding block verification code element is generated to replace the original element.

[0075] Specifically, a foreground object different from the original category or a foreground object of different morphology in the same category is generated. If a foreground object different from the original category is selected, a foreground image meeting the requirements is selected from a corresponding classified storage directory, or a preset model is called to regenerate the foreground image of the category to obtain a foreground object of a new category; if a foreground object of different morphology in the same category is selected, a preset model is called to obtain a foreground object of different morphology in the same category.

[0076] Further, a background image with a differential geometric pattern is generated. The differential geometric pattern refers to a geometric pattern that is different from the geometric pattern in the last generated background image in type, color or parameter. By modifying the prompt word of the preset model, the type, color, size and arrangement parameter of the differential geometric pattern are determined, a new background image is generated by calling the preset model, and the new background image needs to ensure interference and not affect the recognition of the foreground object.

[0077] Further, based on the newly generated foreground object, new irregular shapes and interference irregular shapes are generated according to the methods for generating irregular shapes and interference irregular shapes in S200 to S400. The newly generated foreground object, the background image with the differential geometric pattern and the new interference irregular shape are respectively replaced with the old elements stored in the original sliding block verification code system. After the replacement is completed, when a subsequent user accesses the sliding block verification code, the system will call the new elements to generate the verification code, thereby realizing dynamic updating of the elements and effectively avoiding the drag library attack.

[0078] On the basis of the above-mentioned embodiments, as another optional embodiment, the sliding block verification code generation system comprises: An image generation module is configured to generate a foreground image and a background image. When the foreground image is generated, the foreground object is limited to a common object by a prompt word, and when the background image is generated, the background is limited to containing a geometric pattern by a prompt word. An interference shape module is configured to select another object of the same category as the foreground object, generate an interference irregular shape according to the working logic of the gap generation module, extract the contour points of the interference irregular shape for edge processing, and place the edge-processed interference irregular shape at the center of a blank image of a preset size. An image fusion and sliding block component module is configured to fuse the foreground object after the irregular shape is removed with the background image to obtain a basic image of the sliding block verification code, and generate a first sliding block component 10 and a second sliding block component 20 based on the irregular shape and the interference irregular shape, respectively.

[0079] On the basis of the above-mentioned embodiments, as another optional embodiment, the system further comprises: The mask processing and quadrilateral construction module is responsible for obtaining a mask of the foreground object from the foreground image, randomly selecting an edge of the mask, randomly sampling two points in a preset effective area inside the foreground object, and combining two end points of the selected edge to form a quadrilateral; The gap generation module is responsible for calculating the intersection of the quadrilateral and the mask, and determining a pixel area corresponding to the intersection as an irregular shape of the foreground object. The foreground image classification and screening module is responsible for classifying and saving the generated foreground images according to the categories of common objects, and manually screening the saved foreground images to retain foreground images with clear foreground objects and meeting the requirements of visual identification of verification codes. The update control module is responsible for setting an update trigger condition including a preset time period or a cumulative user access threshold, and controlling the image generation module, the gap generation module, and the interference shape generation module to generate new foreground objects, background images with differentiated geometric patterns, and new interference irregular shapes when the update trigger condition is triggered.

[0080] It should be noted that the system provided in the above embodiments only divides the above functional modules for example to implement its functions. In actual application, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the above described functions. In addition, the system and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process is described in the method embodiment, which will not be described here.

[0081] On the basis of the above embodiments, as another optional embodiment, the present application example can further include a computer storage medium, which can store a plurality of instructions. The instructions are suitable for being loaded and executed by a processor to perform a method of the above embodiments. The specific execution process can be referred to the specific description of the above embodiments, which will not be described here.

[0082] On the basis of the above embodiments, as another optional embodiment, the present application example can further include an electronic device. The electronic device can include at least one processor, at least one communication bus, a user interface, at least one network interface, and a memory.

[0083] The communication bus is used to realize the connection and communication between the components.

[0084] The user interface can include a display screen (Display) and a camera (Camera). Optionally, the user interface can further include a standard wired interface and a wireless interface.

[0085] The network interface can include a standard wired interface and a wireless interface (such as a WI-FI interface).

[0086] The processor can include one or more processing cores. The processor connects various parts within the server through various interfaces and lines, executes various functions of the server and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory, and calling data stored in the memory. Optionally, the processor can be implemented in at least one of a hardware form of a digital signal processing (DSP), a field-programmable gate array (FPGA), and a programmable logic array (PLA). The processor can be integrated with a combination of one or more of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content required to be displayed on the display screen; and the modem is used to process wireless communication. It can be understood that the above-mentioned modem can also not be integrated into the processor, but can be realized by a separate chip.

[0087] The memory can include a random access memory (RAM) and a read-only memory (ROM). Optionally, the memory includes a non-transitory computer-readable storage medium. The memory can be used to store instructions, programs, codes, code sets or instruction sets. The memory can include a program storage area and a data storage area, wherein the program storage area can store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area can store data involved in the above-mentioned various method embodiments, etc. The memory can also be at least one storage device located away from the above-mentioned processor. As a computer storage medium, the memory can include an operating system, a network communication module, a user interface module, and an application program of a method.

[0088] In the electronic device, the user interface is mainly used to provide an interface for the user to input, and obtain data input by the user; and the processor can be used to call an application program stored in the memory and storing a method, which, when executed by one or more processors, causes the electronic device to perform the method of one or more of the above embodiments. It should be noted that, for the foregoing method embodiments, in order to simply describe, they are all described as a combination of a series of actions, but those skilled in the art should know that the present application is not limited to the order of the actions described, because according to the present application, certain steps can be performed in other order or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification all belong to preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0089] In the above embodiments, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments.

[0090] In several embodiments provided in the present application, it should be understood that the disclosed device can be implemented in other ways. For example, the device embodiments described above are only schematic, and the division of units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some service interface, device or unit, and can be electrical or other forms.

[0091] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, that is, they can be located in one place, or can be distributed on a plurality of network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the present embodiment.

[0092] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.

[0093] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable memory. Based on such understanding, the technical solutions of the present application essentially or the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a memory and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the embodiments of the present application. The aforementioned memory includes: a U disk, a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.

[0094] The above are only exemplary embodiments of the present disclosure, and cannot limit the scope of the present disclosure. That is, any equivalent changes and modifications made in accordance with the teachings of the present disclosure are still within the scope of the present disclosure. Other embodiments of the present disclosure will be readily apparent to those skilled in the art upon considering the specification and practicing the true principles of the present disclosure.

[0095] The present application is intended to cover any variations, uses or adaptive changes of the present disclosure that follow the general principles of the present disclosure and include common knowledge or conventional technical means in the technical field not described in the present disclosure. The specification and examples are only considered as exemplary, and the scope and spirit of the present disclosure are defined by the claims.

Claims

1. A method for generating a slider CAPTCHA, characterized in that, The method includes: Foreground and background images are generated using a preset model; Obtain the mask of the foreground object from the foreground image, randomly select one edge of the mask, randomly sample two points within a preset effective area inside the foreground object, and combine the two endpoints of the selected edge to form a quadrilateral. Calculate the intersection of the quadrilateral and the mask; the pixel region corresponding to the intersection is the irregular shape of the foreground object. Select another object of the same category as the foreground object, and generate an interfering irregular shape according to the method for generating irregular shapes described above; The foreground object after removing irregular shapes is fused with the background image to obtain the base image of the slider CAPTCHA. The first slider component and the second slider component are obtained based on the irregular shape and the interfering irregular shape, respectively.

2. The method for generating a slider verification code according to claim 1, characterized in that, The foreground object is a common object, and the categories of common objects include fruits, vegetables, animals, plants, food, daily necessities, etc. After generating the foreground image, the foreground image is classified and saved according to the categories of common objects. The saved foreground images are then manually screened to retain those with clear foreground objects that meet the visual recognition requirements of the verification code.

3. The method for generating a slider verification code according to claim 1, characterized in that, When generating the background image, the prompts for the preset model used include geometric patterns.

4. The method for generating a slider verification code according to claim 1, characterized in that, The process of obtaining the mask of the foreground object from the foreground image includes: The alpha channel of the foreground image is binarized to obtain the mask of the foreground object; Determine the minimum bounding rectangle of the foreground object, crop the foreground object according to the four vertices of the minimum bounding rectangle, and scale the cropped foreground object according to a preset ratio so that the long side of the scaled foreground object is a preset pixel value.

5. The method for generating a slider verification code according to claim 1, characterized in that, The method for sampling within a predetermined effective region inside the foreground object includes: Sampling is performed in the first and second regions along the width of the foreground object. The proportion of pixels at the intersection of the quadrilateral formed after sampling and the mask to the total number of pixels of the corresponding foreground object in the mask is within a preset threshold range.

6. The method for generating a slider verification code according to claim 1, characterized in that, Also includes: Extract the outline points of the irregular shape and the interfering irregular shape, perform outlining processing on the outline points, set the outlining color to a preset color, and place the outlined irregular shape and the interfering irregular shape at the center of a blank image of a preset size.

7. The method for generating a slider verification code according to claim 1, characterized in that, Also includes: Set update trigger conditions, including preset time periods or cumulative user access thresholds; When the update condition is triggered, a foreground object of a different type or a different form of the same type is generated, a background image with differentiated geometric patterns, and irregular shapes and interfering irregular shapes generated based on the updated foreground object are generated.

8. A slider CAPTCHA generation system, characterized in that, The system includes: The image generation module is used to generate foreground and background images. When generating the foreground image, prompts are used to limit the foreground object to a common object, and when generating the background image, prompts are used to limit the background to contain geometric patterns. The interference shape module is used to select another object of the same category as the foreground object, generate an interference irregular shape according to the working logic of the gap generation module, extract the outline points of the interference irregular shape for outlining, and place the outlining interference irregular shape in the center of a blank image of a preset size. The image fusion and slider component module is used to fuse the foreground object after removing irregular shapes with the background image to obtain the base image of the slider verification code, and then generate the first slider component and the second slider component based on the irregular shape and the interfering irregular shape, respectively.

9. An electronic device, characterized in that, It includes a processor, a memory, a user interface, and a network interface. The memory is used to store instructions, the user interface and the network interface are used to communicate with other devices, and the processor is used to execute the instructions stored in the memory to cause the electronic device to perform the method as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a plurality of instructions adapted to be loaded by a processor and executed as described in any one of claims 1-7.