PHP code example of mawuekom / laravel-password-history

1. Go to this page and download the library: Download mawuekom/laravel-password-history library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mawuekom / laravel-password-history example snippets


'providers' => [

    ...

    Mawuekom\PasswordHistory\PasswordHistoryServiceProvider::class,

],



/*
 * You can place your custom package configuration in here.
 */
return [
    
    /**
     * Password histories config
     */
    
    'enable'                    => true,
    'model'                     => Mawuekom\PasswordHistory\Models\PasswordHistory::class,
    'checker'                   => false,
    'number_to_check'           => 3,
    'name'                      => 'Password History',
    'resource_name'             => 'password_history',

    'table'                     => [
        'name'                  => env('PASSWORD_HISTORY_PASSWORD_HISTORIES_DATABASE_TABLE', 'password_histories'),
        'primary_key'           => env('PASSWORD_HISTORY_PASSWORD_HISTORIES_DATABASE_TABLE_PRIMARY_KEY', 'id'),
        'user_foreign_key'      => env('PASSWORD_HISTORY_PASSWORD_HISTORIES_DATABASE_TABLE_USER_FOREIGN_KEY', 'user_id'),
    ],

    /**
     * Users config
     */
    'user' => [
        'model'             => App\Models\User::class,
        'name'              => 'User',
        'resource_name'     => 'user',

        'table'     => [
            'name'          => env('PASSWORD_HISTORY_USERS_DATABASE_TABLE', 'users'),
            'primary_key'   => env('PASSWORD_HISTORY_USERS_DATABASE_TABLE_PRIMARY_KEY', 'id'),
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Add uuid support
    |--------------------------------------------------------------------------
    */

    'uuids' => [
        'enable' => true,
        'column' => '_id'
    ],
];



namespace App\Models;

...
use Mawuekom\PasswordHistory\Traits\HasPasswordHistory;
...

class User extends Authenticatable
{
    use HasPasswordHistory;

    ...
}

$user = User::create([
    'name'      => 'Toto',
    'email'     => '[email protected]',
    'password'  => 'toto1234',
]);

$user ->updatePasswordHistory();

$user = User::find(1);

PasswordHistoryChecker::validatePassword($user, $new_password);
bash
php artisan vendor:publish --tag=password-history
bash
php artisan vendor:publish --tag=password-history --config