Php: your verification code security code? _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Php: your verification code security code ?. Verification codes are mainly used to prevent brute-force cracking, malicious bumping, and automatic submission. I will not describe them here. The type of the verification code also includes numbers, letters, and so on. Verification codes are mainly used to prevent brute-force cracking, malicious bumping, and automatic submission. I will not describe them here. The types of verification codes include numbers, letters, and even Chinese characters. However, no matter how powerful your verification code is, as long as you make the following mistakes in form verification, your verification code will be useless!

The general idea of a verification code is to access a script file at the place where you log in each time. This file generates an image containing the verification code and writes the value to the Session, when submitting the verification code, verify the login script to determine whether the submitted verification code is consistent with that in the Session.

The problem arises. after the login password is incorrect, we will not access the file that generates the verification Image. if the verification code in the Session is not cleared, the verification code will be the same as the previous one, the verification code mechanism, which has been hard-built, is just a false one.

Next let's take a look at the problematic code:
Logon part:

CODE:
Administrator name: Td>
Td>
Tr>

Administrator password: Td>
Td>
Tr>

Verification code: Td>
Td>
Tr>



Td>
Tr>
?> There is no problem here. let's look at the login verification code (I think this verification idea is also used by most people ):

CODE :/*------------------------------------------------------*/
// -- Verify the login information
/*------------------------------------------------------*/
If ($ _ REQUEST ['AC'] = 'signature ')
{
Include ('../includes/cls_captcha.php ');

/* Check whether the verification code is correct */
$ Validator = new captcha ();
If (! $ Validator-> check_word ($ _ POST ['captcha '])
{
Sys_msg ($ _ LANG ['captcha _ error'], 1 );
}

/* Check whether the password is correct */
$ SQL = "SELECT user_id, user_name, password, action_list FROM". $ ecs-> table ('admin _ user ').
"WHERE user_name = '$ _ POST [username]' AND password = '". md5 ($ _ POST ['password']). "'";
$ Row = $ db-> GetRow ($ SQL );

If ($ row)
{
// Login successful
Set_admin_session ($ row ['User _ id'], $ row ['User _ name'], $ row ['action _ list']);

// Update the last logon time and IP address
$ Db-> Execute ("UPDATE". $ ecs-> table ('admin _ user ').
"SET last_time = '". date ('Y-m-d H: I: S', time ()). "', last_ip = '". real_ip (). "'".
"WHERE user_id = $ _ SESSION [admin_id]") OR die ($ db-> ErrorMsg ());

If (isset ($ _ POST ['member'])
{
Setcookie ('ecscp [admin_id] ', $ row [0], time () + 3600*24*360 );
Setcookie ('ecscp [admin_pass] ', md5 ($ row ['password']. $ _ CFG ['hash _ Code']), time () + 3600*24*360 );
}

Header ('Location :./');
}
Else
{
Sys_msg ($ _ LANG ['login _ faild'], 1 );
}
}
?> The problem lies in the above code. after checking the incorrect password, the verification code is not updated, so that we can remove the verification code image on the login page, if you use a URL to access the verification code page, you can submit the user name, password, and the verification code you just obtained to implement brute-force cracking. using this method, you can also implement irrigation and ticket flushing.
You can see the following picture to enhance your understanding.
= 700) window. open ('http: // www.bkjia.com/uploads/alliance131016/05251961k-0.gif'); "src =" http://www.bkjia.com/uploads/allimg/131016/05251961K-0.gif "onload =" if (this. width> '200') this. width = '000000'; if (this. height> '20140901') this. height = '000000'; "border = 0>

Solution: we need to update the verification code after checking the incorrect password. for messages and other types, we also need to update the verification code after the submission is successful.

Security is like this. we always want to make our programs safer, but in general, we can't jump out of the conventional thinking, as a result, many "unconventional vulnerabilities" or "defects" occur in our programs. In short, they are not perfect. In addition to pointing out the problem above, I also hope that everyone can take action and re-examine their programs with an "unconventional" vision, post more small issues that have not been found before, so that everyone can improve them together!

Bytes. The type of the verification code also includes numbers, letters, and so on...

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.