drewlabs/passwords

drewlabs auth 库的密码重置实现

v0.2.20 2023-07-30 10:52 UTC

This package is auto-updated.

Last update: 2024-09-30 02:16:03 UTC


README

密码重置是一种工作流程,允许应用程序用户在不与应用程序连接的情况下修改其连接凭证,即密码。《drewlabs/passwords》是一个不依赖于框架的密码重置工作流程,适用于PHP编程语言,支持基于链接和基于OTP的密码重置。

用法

该库包含用于创建密码重置链接/OTP(一次性密码)的命令类,以及其他用于验证生成的令牌或OTP的命令。

  • 请求密码重置
use Drewlabs\Passwords\Commands\CreatePasswordResetCommand;
use Drewlabs\Passwords\PasswordResetTokenRepository;
use Drewlabs\Passwords\UrlFactory;
use Drewlabs\Passwords\Contracts\TokenInterface;
use Drewlabs\Passwords\Contracts\CanResetPassword;

$repository = new PasswordResetTokenRepository(new Connection('sqlite:memory', 'password_resets'));
$command = new CreatePasswordResetCommand($repository, new CanResetPasswordProvider, 'MySecret');

// Create a password reset link
$command->handle('user@example.com', function(CanResetPassword $user, TokenInterface $token) {
    // TODOL: the command is completed, generate the password reset link
});


//

注意 在上述代码中,CanResetPasswordProvider 是一个假用户解析器实现。库用户必须提供自己的用户解析器,该解析器实现了 Drewlabs\Passwords\Contracts\CanResetPasswordProvider 接口。

  • 生成密码重置OTP

文档正在开发中,任何API更改或功能都将相应添加。

  • 密码重置令牌存储库

《drewlabs/passwords》库包含一个可扩展的重置令牌存储库实现,可以通过创建实现 Drewlabs\Passwords\Contracts\ConnectionInterface 接口的驱动程序进行扩展。