Overview and implementation steps of picture verification code

I Picture verification code overview:

Many websites have this implementation

effect:

In order to improve the security of the system

With the verification code, we can ask the user to input the text on the picture after entering the user name, password and other information. After the user submits, the system will first extract the verification code just generated from the session and compare it with the verification code entered by the user. If the ratio is equal, it means that the user has logged in from the login interface, otherwise, it means that the user is illegal, We use the verification code to ensure that the system can be used only after successful login, so as to avoid users entering the page to be accessed directly in the address bar.

In other words, using the authentication code forces the user to log in from the login interface first

II Verify implementation

Two key classes are used, which are related to the output of pictures

III Implementation steps

1. Use bufferedimage to generate a picture, then use imageio to output it and specify it as JPG format

2. Get picture drawing object

Graphics g = im. getGraphics();

3. Fill the drawing area

4. Output numbers to pictures

5. Random 4 digits

6. Randomly generate Chinese

7. How to import the verification code in the page:

< img ALT = "verification code" SRC = "/ imageservlet" >

8. Save numbers for login comparison

9. Login authentication

First, you need to verify whether the user exists in the database. If so, you also need to verify whether the input verification code is consistent

After successful verification, it needs to be forwarded to the relevant operation page

Code example:

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of programming tips!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>