usu/scrypt-password-encoder-bundle

用于Symfony2的Scrypt密码编码器

v1.0.0 2014-11-29 09:54 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:25:43 UTC


README

此Bundle提供了一种使用Scrypt进行密码编码的Symfony2密码编码器服务。

Build Status Latest Stable Version Total Downloads License

为什么你应该使用scrypt

scrypt密钥派生函数被设计为比PBKDF2或bcrypt等替代函数更安全,更能抵御硬件暴力攻击。

KDF comparison

scrypt的设计者估计,在现代(2009年)的硬件上,如果花费5秒钟来计算派生密钥,针对scrypt的硬件暴力攻击成本大约是针对bcrypt(找到相同的密码)的4000倍,是针对PBKDF2的20000倍。

我已经在使用Bcrypt了!

安装

将以下内容添加到你的composer.json文件中

{
    "require": {
        "usu/scrypt-password-encoder-bundle": "dev-master"
    }
}

然后运行

$ composer update usu/scrypt-password-encoder-bundle

app/AppKernel.php中添加Bundle

$bundles = array(
    // ...
    new Usu\ScryptPasswordEncoderBundle\UsuScryptPasswordEncoderBundle(),
);

最后,在app/config/security.yml中设置编码器

security:
    encoders:
        Symfony\Component\Security\Core\User\User:
            id: security.encoder.scrypt

或者,如果你正在使用优秀的FOSUserBundle

security:
    encoders:
        FOS\UserBundle\Model\UserInterface:
          id: security.encoder.scrypt

配置

你可以通过在你的config.yml文件中添加以下内容来更改默认的Bundle值(如下所示)

usu_scrypt_password_encoder:
    cpu_cost: 2048
    memory_cost: 4
    parallelization_cost: 1
    key_length: 64

更改上述任何参数都将导致不同的密钥(目前不支持旧密码的自动更新)。

参数key_length决定了派生密钥的字节数;例如:64字节密钥会在自动base64_encode后生成88字符的字符串。

请参阅原始文档以获取更多信息。

测试

此Bundle已通过PHPUnit完全测试。

进入根目录,使用composer安装开发依赖项,然后运行phpunit测试套件

$ composer --dev install
$ ./vendor/bin/phpunit

许可证

此Bundle在MIT许可证下发布。请参阅Bundle中的完整许可证。

Resources/meta/LICENSE

致谢

我要感谢elnur创建的优秀的ElnurBlowfishPasswordEncoderBundle,它激发了我发布此Bundle,以及pbhogan,我从其中借用了"为什么你应该使用scrypt"的README部分。