20steps / bricks-scrypt-password-encoder-bundle

适用于 Symfony2 和 Symfony3 的 Scrypt 密码编码器

安装: 252

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 5

分支: 4

类型:symfony-bundle

v1.0.1 2017-01-01 12:26 UTC

This package is not auto-updated.

Last update: 2024-09-28 19:15:22 UTC


README

此 Bundle 提供了一个使用 scrypt 对密码进行编码的 Symfony2 和 Symfony3 密码编码器服务。

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,我从其中借用了 "Why you should use scrypt" 的 README 部分。