php_begins Posted December 13, 2011 Share Posted December 13, 2011 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']) Quote Link to comment https://forums.phpfreaks.com/topic/253111-make-form-field-check-case-insensitive/ Share on other sites More sharing options...
xyph Posted December 13, 2011 Share Posted December 13, 2011 Use strtolower or strtoupper before calling the md5's. Force both to be either all upper or all lowercase. Quote Link to comment https://forums.phpfreaks.com/topic/253111-make-form-field-check-case-insensitive/#findComment-1297599 Share on other sites More sharing options...
php_begins Posted December 13, 2011 Author Share Posted December 13, 2011 i already tried that..but it didnt work: if(strtolower(md5($_POST['security_word'])).'a4xn' == strtolower($_COOKIE['tntcon'])) Quote Link to comment https://forums.phpfreaks.com/topic/253111-make-form-field-check-case-insensitive/#findComment-1297601 Share on other sites More sharing options...
php_begins Posted December 13, 2011 Author Share Posted December 13, 2011 if(strtolower(md5($_POST['security_word']).'a4xn') == strtolower($_COOKIE['tntcon'])) does not work either.. Quote Link to comment https://forums.phpfreaks.com/topic/253111-make-form-field-check-case-insensitive/#findComment-1297605 Share on other sites More sharing options...
php_begins Posted December 13, 2011 Author Share Posted December 13, 2011 could it be because there are numbers in that image too? Quote Link to comment https://forums.phpfreaks.com/topic/253111-make-form-field-check-case-insensitive/#findComment-1297606 Share on other sites More sharing options...
dzelenika Posted December 13, 2011 Share Posted December 13, 2011 md5(strtolower($_POST['security_word'])).'a4xn' or md5(strtolower($_POST['security_word']).'a4xn') Quote Link to comment https://forums.phpfreaks.com/topic/253111-make-form-field-check-case-insensitive/#findComment-1297607 Share on other sites More sharing options...
php_begins Posted December 13, 2011 Author Share Posted December 13, 2011 nope..that doesnt work either... Quote Link to comment https://forums.phpfreaks.com/topic/253111-make-form-field-check-case-insensitive/#findComment-1297609 Share on other sites More sharing options...
php_begins Posted December 13, 2011 Author Share Posted December 13, 2011 the only reason i could think of is it is an md5 behaviour issue.. Quote Link to comment https://forums.phpfreaks.com/topic/253111-make-form-field-check-case-insensitive/#findComment-1297617 Share on other sites More sharing options...
xyph Posted December 13, 2011 Share Posted December 13, 2011 I said before you call the MD5, you have to make the strings the same case. Just use ReCaptcha. It's probably better than the system you have in place. Quote Link to comment https://forums.phpfreaks.com/topic/253111-make-form-field-check-case-insensitive/#findComment-1297622 Share on other sites More sharing options...
Psycho Posted December 13, 2011 Share Posted December 13, 2011 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']) Quote Link to comment https://forums.phpfreaks.com/topic/253111-make-form-field-check-case-insensitive/#findComment-1297634 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.