lajax/yii2-http-auth

Yii2 Http 认证扩展

安装次数: 3,095

依赖者: 0

建议者: 0

安全性: 0

星标: 3

关注者: 3

分支: 1

公开问题: 0

类型:yii2-extension

0.1.0 2016-03-18 16:28 UTC

This package is auto-updated.

Last update: 2024-09-17 21:50:38 UTC


README

Latest Version on Packagist Software License Total Downloads

本扩展可用于保护您的 Yii2 应用程序,通过 HTTP 认证防止未授权访问。例如,您可以使用它来阻止用户查看您的开发环境。

安装

通过 Composer

composer require lajax/yii2-http-auth

使用

您需要在应用程序启动时对组件进行 bootstrap

在执行过程中,组件将检查用户的 IP 地址。如果 IP 地址不在 allowedIps 列表中,将执行 HTTP 认证。

使用 users 选项,您可以指定访问应用程序的用户名和密码对。值可以是实际密码,也可以是密码的 MD5 哈希。

配置

'bootstrap' => ['httpAuth'],
'components' =>  [
    // ...
    'httpAuth' => [
        'class' => 'lajax\httpauth\Component',
        'allowedIps' => ['127.0.0.1', '127.0.0.2'],
        'users' => [
            // Actual password:
            'mrsmith' => '123456',
            // MD5 hash of the password:
            'mrssmith' => 'e10adc3949ba59abbe56e057f20f883e',
        ],
        'errorAction' => 'site/error',
    ],
    // ...
]

测试

composer test

编码风格

项目使用 PSR-2 编码标准。相关命令

  • composer cs-fix:修复编码风格问题。
  • composer cs-check:检查编码风格问题。

变更日志

请参阅 CHANGELOG 了解最近更改的详细信息。

许可证

3-Clause BSD 许可证。请参阅 许可证文件 了解更多信息。