A method and terminal for generating a graphic verification code

By converting digital characters into geometric figures and randomly replacing constituent elements, highly random and difficult to predict graphic verification codes are generated, which solves the problem of insufficient security of existing graphic verification codes and significantly improves the resistance to cracking.

CN119784887APending Publication Date: 2025-04-08FUJIAN HUIZHENGTONG INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411936228.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-04-08

AI Technical Summary

Technical Problem

The existing graphic verification codes are easily cracked by automated programs based on image recognition technology, and their generation process lacks randomness and diversity, resulting in insufficient security.

Method used

By converting numeric characters into geometric figures and randomly replacing their constituent elements, a highly random and unpredictable graph verification code is generated. The method includes selecting numeric characters, creating corresponding geometric figures, randomly replacing constituent elements, drawing to the graphics verification area and generating a unique ID.

Benefits of technology

It significantly enhances the security and cracking resistance of the graphic verification code, and reduces the risk of automatic cracking by the machine by increasing the diversity and unpredictability of the verification code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119784887A_ABST
    Figure CN119784887A_ABST
Patent Text Reader

Abstract

The present invention discloses a method and terminal for generating a graphic verification code, which selects a preset number of numeric characters to form a character string; creates a geometric figure corresponding to the numeric meaning for each numeric character in the character string; randomly replaces the constituent elements of the geometric figure and retains the geometric shape of the geometric figure to obtain a geometric image corresponding to the character string; draws the geometric image to a graphic verification area and generates a graphic verification code, and generates a unique ID associated with the graphic verification code as an identifier. The present invention graphically processes the numeric character string constituting the verification code and randomly replaces the constituent elements in the graphical character string, thereby enhancing the randomness of the generation of the graphic verification code and increasing the difficulty of cracking, thereby improving the security of the use of the graphic verification code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data security, and in particular to a method and a terminal for generating a graphic verification code. Background Art

[0002] With the rapid development of Internet technology, network security issues are becoming increasingly serious. As a common technical means to prevent attacks by robot programs (such as automatic registration, login, etc.), graphic verification codes are widely used in various websites and applications to ensure the legitimacy of users. However, with the continuous advancement of automated attack technology, traditional graphic verification codes have gradually exposed their inadequate security problems, especially their easy cracking by automated programs based on image recognition technology.

[0003] Most existing methods for generating graphic verification codes rely on simply superimposing and distorting numbers or letters with background patterns. Although this can prevent some simple automated attacks, it is still easily recognized by some efficient image recognition algorithms. Many verification codes still have predictable patterns, and the generation process is simple and lacks sufficient randomness, resulting in a high probability that the verification codes can be cracked.

[0004] In addition, the graphic structure of verification codes in the prior art is often relatively simple and cannot effectively enhance its anti-cracking ability. Common graphic verification codes usually contain numeric characters or letters, combined with certain interference elements, such as interference lines and noise points, but the change patterns of these interference elements are relatively fixed and can be easily recognized by machine learning or deep learning algorithms. Summary of the invention

[0005] The technical problem to be solved by the present invention is to provide a method and a terminal for generating a graphic verification code, so as to solve the problem of low security of the graphic verification code. In order to solve the above technical problems, the technical solution adopted by the present invention is: A method for generating a graphic verification code comprises the steps of: S1, selecting a preset number of numeric characters to form a character string; S2, creating a geometric figure corresponding to the digital meaning for each digital character in the string; S3, randomly replacing the constituent elements of the geometric figure and retaining the geometric shape of the geometric figure, to obtain a geometric image corresponding to the character string; S4. Draw the geometric image into the graphic verification area and generate a graphic verification code, and generate a unique ID associated with the graphic verification code as an identifier.

[0006] In order to solve the above technical problems, another technical solution adopted by the present invention is: A terminal for generating a graphic verification code comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor completes the following steps when executing the computer program: S1, selecting a preset number of numeric characters to form a character string; S2, creating a geometric figure corresponding to the digital meaning for each digital character in the string; S3, randomly replacing the constituent elements of the geometric figure and retaining the geometric shape of the geometric figure, to obtain a geometric image corresponding to the character string; S4. Draw the geometric image into the graphic verification area and generate a graphic verification code, and generate a unique ID associated with the graphic verification code as an identifier.

[0007] The beneficial effects of the present invention are: providing a method and terminal for generating a graphic verification code, by graphically processing the digital string constituting the verification code and randomly replacing the constituent elements in the graphical string, thereby enhancing the randomness of the generation of the graphic verification code, increasing the difficulty of cracking, and thus improving the security of the use of the graphic verification code. BRIEF DESCRIPTION OF THE DRAWINGS

[0008] Figure 1 is a flow chart of a method for generating a graphic verification code in an embodiment of the present invention; Figure 2 A schematic diagram of a geometric figure including a number representation of a numeric character in an embodiment of the present invention; Figure 3 Schematic diagram of the geometric pattern of the digital character 1 in the embodiment of the present invention; Figure 4 Schematic diagram of the geometric pattern of the digital character 2 in the embodiment of the present invention; Figure 5 A schematic diagram of a terminal for generating a graphic verification code in an embodiment of the present invention; Description of labels: 1. A terminal for generating a graphic verification code; 2. A memory; 3. A processor. DETAILED DESCRIPTION

[0009] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is an explanation in combination with the implementation modes and the accompanying drawings.

[0010] Please refer to Figure 1 , a method for generating a graphic verification code, comprising the steps of: S1, selecting a preset number of numeric characters to form a character string; S2, creating a geometric figure corresponding to the digital meaning for each digital character in the string; S3, randomly replacing the constituent elements of the geometric figure and retaining the geometric shape of the geometric figure, to obtain a geometric image corresponding to the character string; S4. Draw the geometric image into the graphic verification area and generate a graphic verification code, and generate a unique ID associated with the graphic verification code as an identifier.

[0011] From the above description, it can be seen that the beneficial effects of the present invention are: the present invention provides an innovative method for generating a graphic verification code, which realizes a highly random and unpredictable graphic verification code by converting digital characters into geometric figures and randomly replacing elements. Unlike traditional verification code generation methods, the present invention does not rely on simple pattern changes, but increases the complexity and cracking resistance of the verification code through various geometric element replacements and shape retention. When the graphic verification code is generated by step S4, a unique ID is associated as an identifier, so that each verification code is unique and non-repeatable, thereby ensuring the security of the verification code. This method not only improves the protection capability of the verification code and reduces the risk of being automatically cracked by the machine, but also ensures the uniqueness of the verification code generation, and is suitable for various online scenarios that require verification code protection, such as user registration, login, payment, etc.

[0012] Please refer to Figure 2 In some implementations, step S2 specifically includes: Get the number of each numeric character in the string; A geometric figure stacked by preset figures is created according to the numerical representation.

[0013] As can be seen from the above description, the present invention processes the number representation of each numeric character in the string, and then creates a geometric figure of preset graphic stacking, thereby enhancing the structuring and layering of the verification code. This method can ensure that each numeric character has a corresponding graphic element in the verification code, and the stacking structure of the graphic element has a certain complexity. By adjusting the number of stacking and the composition of the graphics, the image of the verification code is more diverse, avoiding a simple combination of numbers and background patterns, which makes it more difficult to crack the verification code. For example, assuming that the verification code string is "1234", by analyzing the number representation of each numeric character, character 1 is created as a square pattern (preset graphic), character 2 is two square patterns stacked horizontally, character 3 is three square patterns stacked horizontally, and character 4 is two squares stacked in each row for a total of two rows. Each character forms a specific geometric shape by stacking, so that each numeric character is more visually represented, which increases the difficulty of machine recognition.

[0014] Please refer to Figure 3 to Figure 4 Further, the step S3 specifically includes: Create an element library and store multiple graphic elements with unique shape features; Replacing the preset graphics at random positions in the geometric figures and filling them with random graphic elements; The geometric shape of the geometric figure is retained, and a geometric image corresponding to the character string is obtained.

[0015] From the above description, we can see that by creating an element library and replacing elements at random positions in the geometric figures, the geometric shape is retained, thereby enhancing the variability and graphic complexity of the verification code. By building an element library with unique shape features, it can be ensured that each geometric image is unique, and the replaced graphics can still maintain the recognizability of the geometric shape. This not only improves the defense capability of the verification code, but also adds flexibility and diversity to the generation of verification code graphics. For example, in the element library, geometric elements of different sizes and shapes, such as circles, squares, and stars, may be included. For the number "5", the system can randomly select a suitable geometric element to replace a part of the graphic, while ensuring that the structure and appearance of the entire graphic remain consistent, preventing the cracking algorithm from identifying through regularity.

[0016] In some implementations, step S4 further includes: The geometric image is rotated at a random angle and then drawn into the graphic verification area.

[0017] From the above description, it can be seen that step S4 further adds the operation of randomly rotating the geometric image. By rotating the geometric image at random angles, the difficulty of intelligent machine recognition and the risk of cracking are increased, making the automated cracking technology more difficult. This method effectively avoids image recognition attacks based on fixed angles and provides a safer verification method. For example, after generating a verification code, the system will rotate each geometric figure at a random angle to ensure that the verification code figure has no visual regularity.

[0018] In some implementations, the step S4 further includes: The graphic verification area after drawing is detected, and if there is an overlap of the geometric images, the overlapping geometric images are adaptively scaled and then redrawn to the graphic verification area.

[0019] From the above description, it can be seen that if there is geometric image overlap in the graphic verification area after drawing, adaptive scaling and redrawing can effectively avoid the overlap of the verification code graphics and ensure its clarity. This method ensures that the generated graphic verification code will not be difficult to recognize characters due to the image being too dense, thereby improving the usability of the verification code.

[0020] Please refer to Figure 5A terminal for generating a graphic verification code comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor completes the steps in a method for generating a graphic verification code when executing the computer program.

[0021] The present invention provides a method and a terminal for generating a graphic verification code, which are mainly used to improve the security of using the graphic verification code, and are specifically described below in conjunction with embodiments.

[0022] Please refer to Figure 1 , Embodiment 1 of the present invention is: A method for generating a graphic verification code comprises the steps of: S1, selecting a preset number of numeric characters to form a character string; S2, creating a geometric figure corresponding to the digital meaning for each digital character in the string; S3, randomly replacing the constituent elements of the geometric figure and retaining the geometric shape of the geometric figure, to obtain a geometric image corresponding to the character string; S4. Draw the geometric image into the graphic verification area and generate a graphic verification code, and generate a unique ID associated with the graphic verification code as an identifier.

[0023] Specifically, the preset number is 4. When a user requests a graphic verification code, the server randomly selects four numbers from the digital characters 1-9 as the verification code string, and correspondingly generates four geometric figures corresponding to the meaning of the numbers. The constituent elements of each figure are randomly replaced, such as shape elements such as solid circles, squares or five-pointed stars, which not only forms a unique geometric figure, but also ensures the unpredictability of the figure, thereby greatly enhancing the security of the verification code.

[0024] Please refer to Figures 2 to 4 , Embodiment 2 of the present invention is: Based on the first embodiment, the step S2 specifically includes: Get the number of each numeric character in the string; A geometric figure stacked by preset figures is created according to the numerical representation.

[0025] The step S3 specifically includes: Create an element library and store multiple graphic elements with unique shape features; Replacing the preset graphics at random positions in the geometric figures and filling them with random graphic elements; The geometric shape of the geometric figure is retained, and a geometric image corresponding to the character string is obtained.

[0026] That is, a geometric figure composed of preset graphics is generated for each numeric character. The geometric figure contains the number representation of each character. Subsequently, the preset graphics in the geometric figure are randomly replaced with the graphic elements in the element library, that is, the geometric figure is created and the constituent elements of the geometric figure are replaced. The string undergoes two random changes, which improves the defense capability of the verification code and increases the flexibility and diversity of the generation of verification code graphics. For example, the element library may contain geometric elements of different sizes and shapes, such as circles, squares, and stars. For the number "5", the system can randomly select a suitable geometric element to replace a part of the graphic, while ensuring that the structure and appearance of the entire graphic remain consistent, preventing the cracking algorithm from identifying through regularity.

[0027] Embodiment 3 of the present invention is: Based on the first embodiment, the step S4 further includes: The geometric image is rotated at a random angle and then drawn into the graphic verification area.

[0028] The graphic verification area after drawing is detected, and if there is an overlap of the geometric images, the overlapping geometric images are adaptively scaled and then redrawn to the graphic verification area.

[0029] By rotating the geometric image at random angles, the difficulty of intelligent machine recognition and the risk of cracking are increased, making automated cracking technology more difficult. This method effectively avoids image recognition attacks based on fixed angles and provides a safer means of verification. For example, after generating a verification code, the system will rotate each geometric figure at a random angle to ensure that the verification code figure has no visual regularity. At the same time, if there is overlap of geometric images in the graphic verification area after the rotation, adaptive scaling and redrawing can effectively avoid overlap of the verification code figure and ensure its clarity. This method ensures that the generated graphic verification code will not make the characters difficult to recognize due to the image being too dense, thereby improving the usability of the verification code.

[0030] Embodiment 4 of the present invention is: A method for generating a graphic verification code is specifically applied as follows: 1. The client requests the server to obtain a graphic verification code. (II) The server receives the request from the client and generates a graphic verification code. The specific steps are as follows: (1) Get the width imgWidth (px) and height imgHeight (px) of the graphic verification code from the system configuration.

[0031] (2) Generate an image captchaImg in memory with a width of imgWidth (px), a height of imgHeight (px) and a transparent background; (3) Randomly select 4 numbers from the numeric characters "1-9" as the verification code string captchaStr in the graphic verification code.

[0032] (4) Randomly select a background image from the graphic QR code background image library and draw it in the image captchaImg just generated. When drawing the background image, fill the entire image captchaImg with the selected background image.

[0033] (5) Randomly select a color and use it to draw an interference curve on the image captchaImg. (6) Set a random color captchaColor as the color of the current drawing environment of the image captchaImg.

[0034] (7) Let the top margin, bottom margin, left margin and right margin of the graphic verification code string captchaStr and the image captchaImg be marginTop, marginBottom, marginLeft and marginRight respectively, and the spacing between characters in the verification code string captchaStr be marginChar, all in px.

[0035] (8) Figure 3 As shown, an element library is created and three graphic elements with unique characteristics are stored; Select a numeric character n in sequence from the captchaStr string, and randomly select one from the 3^n geometric shape images corresponding to the numeric character n, recorded as captchaShape. That is, for each element in the geometric shape image corresponding to the numbers 1 to 9, there are three forms: solid circle, solid square, and solid five-pointed star. For each number from 1 to 9, there are 3^n geometric shape images corresponding to it; Figure 3-4 There are 3 geometric patterns for character 1 and 9 geometric patterns for character 2.

[0036] (9) Randomly rotate captchaShape by an angle α, α∈[0,π]. Ensure that the width of the rotated captchaShape is less than or equal to (imgWidth –marginLeft –marginRight) / 4 –marginChar, and the height is less than or equal to (imgHeight –marginTop –marginBottom). If the width or height of the rotated captchaShape exceeds the above range, it is appropriately scaled to avoid overlapping of the geometric figures generated by the characters.

[0037] (10) Draw the captchaShape in captchaImg, making sure that the captchaShapes corresponding to all the numeric characters n in captchaStr do not overlap. If there is any overlap, the relevant characters are adaptively scaled.

[0038] (11) Repeat (6) to (10) until all characters in the graphic verification code string captchaStr are drawn.

[0039] (12) Generate a globally unique ID and use the ID as the Key and the graphic verification code string captchaStr as the Value and store them in the cache (which can be a local cache or a distributed cache).

[0040] (11) Send the globally unique ID and the image captchaImg corresponding to the graphic verification code to the client.

[0041] Please refer to Figure 5 , Embodiment 5 of the present invention is: A terminal 1 for generating a graphic verification code comprises a memory 2, a processor 3 and a computer program stored in the memory 2 and executable on the processor 3. When the processor 3 executes the computer program, the steps in the method for generating a graphic verification code are completed.

[0042] The graphic verification code generation method of the present invention significantly improves the security, complexity and usability of the verification code through multiple innovative steps. In summary, the method has the following beneficial effects: First, by converting digital characters into geometric shapes and randomly replacing their constituent elements (such as circles, squares, five-pointed stars, etc.), the diversity and unpredictability of the verification code are effectively increased, making the graphic verification code more complex in both visual and structural aspects, thereby enhancing its anti-cracking ability. Each digital character corresponds to a preset geometric shape, and by randomly selecting and replacing elements of different shapes, simple and fixed patterns are avoided, greatly improving the security of the verification code.

[0043] Secondly, the geometric figures generated by stacking graphics have a sense of hierarchy and structure, so that each digital character can be clearly corresponded in the graphics, thereby enhancing the complexity of the verification code image. This kind of graphic stacking and composition makes the verification code difficult to crack through simple image analysis or pattern recognition algorithms, and is particularly suitable for preventing automated attacks.

[0044] In addition, the present invention creates an element library with unique shape features and performs random rotation, scaling and other processing on geometric figures, so that the generated verification code graphics are more difficult to predict, and each verification code image is unique and highly resistant to recognition. Random rotation angles and adaptive scaling avoid graphic duplication and overlap, thereby ensuring the clarity and readability of the verification code and avoiding visual confusion caused by graphic interlacing.

[0045] In addition, the generated graphic verification code is associated with a globally unique ID, which enhances the identification and security of the verification code. By storing the ID in the cache system, the server can accurately verify the verification code entered by the user and prevent the verification code from being maliciously tampered with or reused, thereby improving the protection capability of the entire system.

[0046] In summary, the present invention not only improves the anti-cracking ability of the graphic verification code, but also improves the generation efficiency, readability and user experience of the verification code, while ensuring the uniqueness and unpredictability of each verification code, and adapts to modern information security requirements.

[0047] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A method for generating a graphic verification code, characterized in that: Includes steps: S1, selecting a preset number of numeric characters to form a character string; S2, creating a geometric figure corresponding to the digital meaning for each digital character in the string; S3, randomly replacing the constituent elements of the geometric figure and retaining the geometric shape of the geometric figure, to obtain a geometric image corresponding to the character string; S4. Draw the geometric image into the graphic verification area and generate a graphic verification code, and generate a unique ID associated with the graphic verification code as an identifier.

2. The method for generating a graphic verification code according to claim 1, characterized in that: The step S2 specifically includes: Get the number of each numeric character in the string; A geometric figure stacked by preset figures is created according to the numerical representation.

3. A method for generating a graphic verification code according to claim 2, characterized in that: The step S3 specifically includes: Create an element library and store multiple graphic elements with unique shape features; Replacing the preset graphics at random positions in the geometric figures and filling them with random graphic elements; The geometric shape of the geometric figure is retained, and a geometric image corresponding to the character string is obtained.

4. The method for generating a graphic verification code according to claim 1, characterized in that: The step S4 further comprises: The geometric image is rotated at a random angle and then drawn into the graphic verification area.

5. The method for generating a graphic verification code according to claim 1, characterized in that: After step S4, the following steps are also included: The graphic verification area after drawing is detected, and if there is an overlap of the geometric images, the overlapping geometric images are adaptively scaled and then redrawn to the graphic verification area.

6. A terminal for generating a graphic verification code, characterized in that: The invention comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the following steps are performed: S1, selecting a preset number of numeric characters to form a character string; S2, creating a geometric figure corresponding to the digital meaning for each digital character in the string; S3, randomly replacing the constituent elements of the geometric figure and retaining the geometric shape of the geometric figure, to obtain a geometric image corresponding to the character string; S4. Draw the geometric image into the graphic verification area and generate a graphic verification code, and generate a unique ID associated with the graphic verification code as an identifier.

7. A terminal for generating a graphic verification code according to claim 6, characterized in that: The step S2 specifically includes: Get the number of each numeric character in the string; A geometric figure stacked by preset figures is created according to the numerical representation.

8. A terminal for generating a graphic verification code according to claim 7, characterized in that: The step S3 specifically includes: Create an element library and store multiple graphic elements with unique shape features; Replacing the preset graphics at random positions in the geometric figures and filling them with random graphic elements; The geometric shape of the geometric figure is retained, and a geometric image corresponding to the character string is obtained.

9. A terminal for generating a graphic verification code according to claim 6, characterized in that: The step S4 further comprises: The geometric image is rotated at a random angle and then drawn into the graphic verification area.

10. A terminal for generating a graphic verification code according to claim 6, characterized in that: After step S4, the following steps are also included: The graphic verification area after drawing is detected, and if there is an overlap of the geometric images, the overlapping geometric images are adaptively scaled and then redrawn to the graphic verification area.