How to handle verification code bypass _ PHP Tutorial

Source: Internet
Author: User
The handling method of the verification code being bypassed. First, let's analyze the process 1 with the verification code released, Display Form 2, display the verification code (the program that generates the verification code), encrypt the verification code, and put it into session or cookie3, let's analyze the verification code release process.
1. display the form
2. display the verification code (a program that generates the verification code). encrypt the verification code and put it into the session or cookie.
3. the user submits the form.
4. check that the verification code is correct. write the data to the database after the data is valid.

If the user publishes another one, the user will normally access the form page again. The verification code image is updated passively, and the session and cookie will change accordingly.
However, the water filling machine does not have to use a form page. it can directly simulate post to send data to the server program. in this way, the verification code program is not called, of course, the encryption verification code stored in the session and cookie is the last value and is not updated. in this way, the data sent directly through post is unlimited in the future, regardless of the verification code. the verification code is also false!

Therefore, after verifying the verification code, clear the session and cookie values, and then determine the validity of the data!
Such a vulnerability is replaced!

If (md5 ($ _ post ['vcode']) = $ _ session ['vcode']) {
$ _ Session ['vcode'] = ''; // This sentence is very important.
} Else {
Exit 'incorrect verification code! ';
}
// Subsequent processing
......
?>

Program for generating verification code images

Session_start ();
......
$ V = new authcode ();
$ Vcode = $ v-> getauthcode ();
$ _ Session ['vcode'] = md5 ($ vcode );
........
?>

Form page


How the verification code is bypassed

When 1, Display Form 2, display the verification code (a program that generates the verification code), encrypt the verification code and put it into session or cookie 3 ,...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.