laminas / laminas-captcha

Generate and validate CAPTCHAs using Figlets, images, ReCaptcha, and more
https://docs.laminas.dev/laminas-captcha/
BSD 3-Clause "New" or "Revised" License
24 stars 13 forks source link

Standalone ZF2 forms: Captcha Dumb value is always wrong #4

Open weierophinney opened 4 years ago

weierophinney commented 4 years ago

This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7098 User: @developer10 Created On: 2015-01-04T12:53:51Z Updated At: 2015-01-05T10:27:52Z Body I first tried to use it without session at all but then included it like so:

$sessionManager = new Zend\Session\SessionManager();
$sessionManager->start();

After I enter the "word" my session outputs:

[Zend_Form_Captcha_0567fd5c45db3ad9136610ee3e10d71a] => Zend\Stdlib\ArrayObject Object
        (
            [storage:protected] => Array
                (
                    [word] => 74c74
                )

            [flag:protected] => 2
            [iteratorClass:protected] => ArrayIterator
            [protectedProperties:protected] => Array
                (
                    [0] => storage
                    [1] => flag
                    [2] => iteratorClass
                    [3] => protectedProperties
                )

        )

but the problem is that getMessages contains (see below) as if the word was entered incorrectly. I tried entering both backwards and normal way, the result is always the same: Captcha value is wrong

Array
(
    [captcha] => Array
        (
            [badCaptcha] => Captcha value is wrong
        )

)

Comment

User: @Ocramius Created On: 2015-01-05T00:38:43Z Updated At: 2015-01-05T00:38:43Z Body Requires an actual failing test case, I'd say. Session issues are always tricky to handle, therefore I suggest writing a small test.


Comment

User: @developer10 Created On: 2015-01-05T10:27:52Z Updated At: 2015-01-05T10:27:52Z Body This may not be a bug or anything after all. I have put some print_r() in the class AbstractWord to see what the input value is actually compared to.

$this->id = $value['id']; if ($input !== $this->getWord()) {

        echo '<pre>';
        print_r("Input: " . $input);
        print_r(" | getWord: " . $this->getWord());
        echo '</pre>';

        $this->error(self::BAD_CAPTCHA);
        return false;

The following happens:

The word is created, user inputs the value in the captcha field. But then when my form is submitted, a new request is being made so that the captcha input is actually being compared to the new word (from that subsequent request).

I assume I'm doing something incorrectly because I intentionally fill the other fields incorrectly and try to get the validation errors appear. They don't appear at all (maybe because of that new request; also my form is blank after that) and the only way I can see the errors is by outputting them below the form by calling echo on $form->getMessages().

Bearing in mind I'm implementing a standalone form and having a custom InputFilter class - why my form is submitting and the errors (including captcha one) are not appearing even though field values are incorrect?



Originally posted by @GeeH at https://github.com/zendframework/zend-captcha/issues/22