|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
CMellor Smarty Rookie
Joined: 22 Aug 2007 Posts: 8
|
Posted: Sat Oct 06, 2007 8:06 pm Post subject: Validate CAPTCHA |
|
|
Hey,
I'm using the Captcha plugin with Smarty, but I can't for the life of me work out how to validate it to check if the input is correct.
I though this might do it:
Code: |
// Check if captcha matches
if(md5($_POST['captcha_confirm']) == $_POST['captcha']) {
echo(1);
}
else {
echo(0);
} |
But it doesn't.
Any help on this is appreciated. |
|
Back to top |
|
XP_Prem Smarty Regular
Joined: 22 Jul 2005 Posts: 37
|
Posted: Sun Oct 07, 2007 2:46 am Post subject: |
|
|
why md5? |
|
Back to top |
|
CMellor Smarty Rookie
Joined: 22 Aug 2007 Posts: 8
|
Posted: Sun Oct 07, 2007 4:31 pm Post subject: |
|
|
Why not? I assume to get the value of the hidden input, which is 32 characters in length, which is what is outputted when you md5 something, I'd have to md5 the value I typed in which matches the captcha code.
If I'm wrong, please correct me. |
|
Back to top |
|
CMellor Smarty Rookie
Joined: 22 Aug 2007 Posts: 8
|
Posted: Sun Oct 07, 2007 5:53 pm Post subject: |
|
|
So yeah, I figured out there was a function that checks the codes, but that hasn't helped the situation. I tried this method:
Code: | // Assign CAPTCHA
define('CAPTCHA_SALT', 'blah');
// Check if captcha matches
if(validate_captcha($_POST['captcha'], $_POST['captcha_confirm'])) {
echo 1;
}
else {
echo 0;
} |
But still nothing...
When I look at this function:
Code: | function validate_captcha($md5, $code){
$shouldbe = md5($code . CAPTCHA_SALT . 'some salt' . $code .CAPTCHA_SALT . 'extra salt');
return ($shouldbe == $md5);
} |
I wonder if most of that $shouldbe variable is even necessary. |
|
Back to top |
|
pstamb Smarty Rookie
Joined: 29 Jan 2007 Posts: 7
|
Posted: Sun Oct 07, 2007 7:46 pm Post subject: |
|
|
Please check the validate.php file in the zip file. There you will see how it's done. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|