timur-flush/sofa-csrf

该库旨在为Phalcon应用程序提供软csrf保护。

v1.0.0 2018-07-09 03:14 UTC

This package is auto-updated.

Last update: 2024-09-15 01:04:47 UTC


README

该库旨在为Phalcon应用程序提供软csrf保护。

请注意

令牌在当前会话中是永久的。即使令牌输入错误,当前会话中也不会更新。

使用

//in Dependency Injection
$di->setShared(
    'csrf',
    function() {
        //The variable must store the value of interface \Phalcon\Session\AdapterInterface
        $sessionAdapter = $this->getSession();
        
        return new \TimurFlush\SofaCsrf\Protection($sessionAdapter);
    }
);

//in form
class form extends \Phalcon\Form
{
    public function initialize()
    {
        $csrf = new Hidden('csrf_token');
        $csrf->addValidator(
            new \TimurFlush\SofaCsrf\Validator\Csrf(
                [
                    'message' => 'Invalid csrf. Try again!'
                    //option 'cancelOnFail' is already installed
                ]
            )
        );
    }
}

许可证

BSD-3-Clause

版本

2.0.0-B1

作者

Timur Flush

电子邮箱: flush02@tutanota.com

Telegram: @flush02