raditzfarhan/laravel-user-security

为用户添加安全码、助记键和双因素认证功能。

安装: 708

依赖者: 0

建议者: 0

安全: 0

星级: 2

关注者: 1

分支: 1

公开问题: 0

类型:laravel-package

v1.0.0 2020-04-18 01:54 UTC

This package is auto-updated.

Last update: 2024-09-06 05:57:39 UTC


README

License styleci

Laravel 用户安全 - RFAuthenticator

为用户添加安全码、助记键和双因素认证功能。

安装

通过Composer

$ composer require raditzfarhan/laravel-user-security:^1.0

配置

由于Laravel和Lumen的配置略有不同,因此这里提供每个框架的安装说明。

Laravel

编辑config/app.php文件,并添加以下行以注册服务提供者

'providers' => [
    ...
    RaditzFarhan\UserSecurity\UserSecurityServiceProvider::class,
    ...
],

提示:如果您使用的是Laravel 5.5或更高版本,可以跳过此部分的设置,改用自动发现功能。

Lumen

编辑bootstrap/app.php文件,并添加以下行以注册服务提供者

...
$app->register(RaditzFarhan\UserSecurity\UserSecurityServiceProvider::class);
...

您还需要在bootstrap/app.php中启用Facades

..
$app->withFacades(true, [
    ...
    RaditzFarhan\UserSecurity\Facades\RFAuthenticator::class => 'RFAuthenticator'
]);
...

打开您的用户提供者模型类,例如App\User,并添加RaditzFarhan\UserSecurity\Traits\UserSecurable特性

<?php

namespace App;

...
use RaditzFarhan\UserSecurity\Traits\UserSecurable;

class User extends Model implements AuthenticatableContract, AuthorizableContract
{
    ...
    use UserSecurable;
    ...
}

用法

以下为示例用法

// to add/update security pin for eloquent user
$user->updateSecurityPin($security_pin);

// to add/update entropy for eloquent user
$user->updateEntropy($entropy);

// to add/update multiple authenticators
$user->updateMultipleAuthenticators(['security_pin' => $security_pin, 'mnemonic_entropy' => $entropy]);

要使用助记函数,示例如下

// Success response

// using service container to generate mnemonic object
$mnemonic = app('RFAuthenticator')->mnemonic()->generate();

// using alias to generate mnemonic object
$mnemonic = \RFAuthenticator::mnemonic()->generate();

// Use mnemonic codes to find entropy
$mnemonic = \RFAuthenticator::mnemonic()->words($words);

// Generate Mnemonic using specified Entropy
$mnemonic = \RFAuthenticator::mnemonic()->entropy($entropy);

变更日志

请参阅变更日志以获取有关最近更改的更多信息。

致谢

许可

MIT。请参阅许可文件以获取更多信息。