robsonala/laravel-crypto-user

此包已被弃用且不再维护。未建议替代包。

Laravel 的加密工具,与用户表连接,包括对 Eloquent 的支持

0.3.4 2019-11-12 12:21 UTC

This package is auto-updated.

Last update: 2020-01-23 10:37:42 UTC


README

Laravel 的加密工具,与用户表连接,包括对 Eloquent 的支持

Build Status

安装

php artisan vendor:publish
// Select `Robsonala\CryptoUser\CryptoUserProvider`
php artisan migrate

教程

步骤 1 - 在用户模型上设置 'UserEncrypt 特性'

...
use Robsonala\CryptoUser\Traits\UserEncrypt;
...
use Notifiable, UserEncrypt;
...

步骤 2 - 为用户创建注册密钥 (RegisterController.php)

...
use Robsonala\CryptoUser\Services\Actions;
...
protected function create(array $data)
{
    $user = User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
    ]);

    Actions::register($user, $data['password']);

    return $user;
}
...

步骤 3 - 用户登录时在内存中设置密钥 (LoginController.php)

...
use Robsonala\CryptoUser\Services\Actions;
...
protected function authenticated($request, $user)
{
    Actions::login($user, $request->password);
}
...

步骤 4 - 在每个所需模型上设置 'CryptData 特性'

...
use Robsonala\CryptoUser\Traits\CryptData;
...
use CryptData;

protected $crypt_attributes = [
    'name'
];
...

额外功能

每次更新用户密码时都必须使用该密钥

...
use Robsonala\CryptoUser\Services\Actions;
...
$old = $request->get('current-password');
$new = $request->get('new-password');

$user = Auth::user();

Actions::updatePassword($user, $old, $new);
...

与另一个用户共享用户的短语

...
use Robsonala\CryptoUser\Services\Actions;
...

// Owner of the passphrase
$user = Auth::user();
$user_passphrase = '...';

// User that will receive the passprhase
$another_user = User::find(...);

Actions::sharePassphrase($user, $another_user, $user_passphrase);
...

待办事项

  • 创建适当的文档

许可

MIT