...

View Full Version : Captcha validation not working



Acute Chaos
02-22-2012, 03:57 PM
I have a simple login form - user name, password, captcha code field and a submit. It is fine and good to go.

I have separate file creating the captcha image and setting a Session with the captcha code in it. It is fine and good to go.

I have the third file that executes everything.

If I log in accurately everything works well.

I have validation for the three fields in the form:




$name = clean($_POST['name']);
$pass = clean($_POST['password']);
$capcode = clean($_POST['security']);
$code = $_SESSION['security_code'];


if($name == '') {
$errmess_arr[] = 'Your username was missing';
$erralert = true;
}
if($pass == '') {
$errmess_arr[] = 'Your password was missing';
$erralert = true;
}
if($capcode == '') {
$errmess_arr[] = 'You need to fill in the security code';
$erralert = true;
}
if( strcmp($capcode, $code) != 0 ) {
$errmsg_arr[] = 'The security code you entered did not match the security code showing. Please try again.';
$erralert = true;
}
if($erralert) {
$_SESSION['error'] = $errmess_arr;
session_write_close();
header("location: loginfail.php");
exit();
}





If I miss filling in any one, two or all three of the fields the validation works perfectly.

BUT if the code filled in doesn't match the captcha image I don't get the alert message. It doesn't log in the way it shouldn't if the code is wrong, all that code works fine. But I've been banging my head against the wall trying to figure out why the comparison validation message doesn't show up like the rest do.

I echoed the session to see if it was setting right and it is.

EVERYTHING works the way it should except for this.

The user is redirected to the right page but the message doesn't display like it does for the other validation checks.

Any ideas? Let me know if you need the rest of the code but I thought this would be enough.

Thanks.

Rowsdower!
02-22-2012, 04:01 PM
A second set of eyes never hurts. You're going to kick yourself:


if( strcmp($capcode, $code) != 0 ) {
$errmsg_arr[] = 'The security code you entered did not match the security code showing. Please try again.';
$erralert = true;
}

Acute Chaos
02-22-2012, 04:20 PM
You know how many $%^& times I looked at that.

I double checked I had that right so many times and and just glazed over it because mess=message msg=message ...

Thanks a lot - lol. That is the problem with working on your own sometimes. A fresh set of eyes can take 15 seconds to save you a couple hours.

Thanks for your help!

Of course it works now - btw

:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum