Jump to content

make form field check case insensitive


php_begins

Recommended Posts

I am using a captcha like image verification for my form fields.

I want to make my check case insensitive:

For example,

if the security word is 1A3e then 1a3e or 1a3E should work.(Upper Case or lower case does not matter)

Here is the check I am doin so far to see if my security word matches.

 

if(md5($_POST['security_word']).'a4xn' == $_COOKIE['tntcon'])

Link to comment
Share on other sites

You will ONLY be able to do this if the value in the cookie ($_COOKIE['tntcon']) was set to lower or upper case before BEFORE creating the MD5() value. You MUST get the user input in the exact same case as was used to create the validation value.

 

So, you will need to update the code that sets the cookie value AND update the code to check the POST value against the cookie value. Since you need to do the same thing in two different places you should create a function so you are guaranteed to be doing the exact same thing in both instances.

 

function createChecksum($code, $salt)
{
    return md5(strtolower(trim($code)).$salt);
}

 

Creating the value to store in the cookie

$tntcon = createChecksum($captchaCode, 'a4xn');
setcookie("tntcon", $tntcon, time()+300); //5 minutes

 

Verify user input

if(createChecksum($_POST['security_word'], 'a4xn') == $_COOKIE['tntcon'])

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.