starfolksoftware/password-history

此包已被弃用,不再维护。没有建议的替代包。

将密码历史添加到您的laravel应用程序

v0.6.1 2020-10-15 00:07 UTC

This package is auto-updated.

Last update: 2021-08-15 02:00:16 UTC


README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

将密码历史添加到您的laravel应用程序

安装

您可以通过composer安装此包

composer require starfolksoftware/password-history

您可以使用以下命令发布和运行迁移

php artisan vendor:publish --provider="StarfolkSoftware\PasswordHistory\PasswordHistoryServiceProvider" --tag="migrations"
php artisan migrate

您可以使用以下命令发布配置文件

php artisan vendor:publish --provider="StarfolkSoftware\PasswordHistory\PasswordHistoryServiceProvider" --tag="config"

这是发布配置文件的内容

[
    /*
    * When using the "HasPasswordHistory" trait from this package, we need to know which
    * Eloquent model should be used to retrieve your roles. Of course, it
    * is often just the "PasswordHistory" model but you may use whatever you like.
    *
    * The model you want to use as a PasswordHistory model needs to implement the
    * `StarfolkSoftware\PasswordHistory\Contracts\PasswordHistory` contract.
    */
    'password_history_class' => \StarfolkSoftware\PasswordHistory\PasswordHistory::class,

    /**
     * The table name for password histories.
     */
    'table_name' => 'password_histories',

    /**
     * The models password column name
     */
    'models_password_column_name' => 'password',

    /**
     * Password change can not be the same with any password in the last 
     * {{ password_history_check_length }} recent passwords
     */
    'password_history_check_length' => env('PASSWORD_HISTORY_CHECK_LENGTH', 5),

    /*
    * The user model that should be used. If null, the default user provider from your
    * Laravel authentication configuration will be used.
    */
    'user_model' => \Illuminate\Foundation\Auth\User::class,
]

使用方法

注册模型

使用此包,您可以跟踪任何模型的密码历史。要使您的模型具有 passwordhistorable 功能,请将 HasPasswordHistory 添加到模型类中,如下所示

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use StarfolkSoftware\PasswordHistory\Traits\HasPasswordHistory;

class User extends Model
{
    use HasPasswordHistory;
    ...
}

当您的模型上触发 saved 事件时,密码历史将保存到数据库中。请注意,在首次创建模型时也会触发 saved 事件。

NotInRecentPasswordHistory 验证规则

如果您想验证密码不在最近的密码历史中,可以使用以下代码片段中的 NotInRecentPasswordHistory 规则

use StarfolkSoftware\PasswordHistory\Rules\NotInRecentPasswordHistory;

validator(collect($model)->toArray(), [
    'password' => NotInRecentPasswordHistory::ofUser($model),
])->validate();

测试

composer test

Psalming

./vendor/bin/psalm --show-info=true

变更日志

有关最近更改的更多信息,请参阅变更日志

贡献

有关详细信息,请参阅贡献指南

安全漏洞

请参阅我们的安全策略了解如何报告安全漏洞。

鸣谢

许可证

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