PHP code example of sicaboy / laravel-security

1. Go to this page and download the library: Download sicaboy/laravel-security 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/ */

    

sicaboy / laravel-security example snippets


Siaboy\LaravelSecurity\LaravelSecurityServiceProvider::class,

// Add rule instance to the field validation rules list
public function rules()
{
    return [
        'password_field' => [
            ' 'regex:/[A-Z]/',      // must contain at least one uppercase letter
            'regex:/[0-9]/',      // must contain at least one digit
            //...
            new \Sicaboy\LaravelSecurity\Rules\NotCommonPassword(),
            new \Sicaboy\LaravelSecurity\Rules\NotAUsedPassword($user),
        ],
    ];
}
// Also you need to call event, examples in the next section

// Call on user password change
event(new \Illuminate\Auth\Events\PasswordReset($user));

// If you are using custom login, register and reset password actions which are not the Laravel built-in ones, you will need to call event in your function accordingly.
event(new \Illuminate\Auth\Events\Login($user)); 
event(new \Illuminate\Auth\Events\Registered($user));
event(new \Illuminate\Auth\Events\PasswordReset($user)); 

...
'password_policy' => [
    // Delete accounts with days of no activity
    'auto_delete_inactive_accounts' => [
        'enabled' => true,
        ...
    ],

    // Lock out accounts with days of no activity
    'auto_lockout_inactive_accounts' => [
        'enabled' => true,
        ...
    ],
]
...

Route::middleware(['security'])->group(function () {
    ...
});

Route::middleware(['security:admin'])->group(function () {
  ...
});

 return [
     'default' => [
         ...
     ],
     'group' 
         'admin' => [ // Example, when using middleware 'security:admin'. Attributes not mentioned will be inherit from `default` above
            ...
         ],
         'other_name' => [ // Middleware 'security:other_name'
             ...
         ]
     ],
 

...
'password_policy' => [
    ...
    // Force change password every x days
    'force_change_password' => [
        'enabled' => true,
        'days_after_last_change' => 90, // every 90 days
        'change_password_url' => '/user/change-password', // Change My Password page URL
    ],
    ...
]
...

protected function schedule(Schedule $schedule)
{
    $schedule->command(\Sicaboy\LaravelSecurity\Console\Commands\DeleteInactiveAccounts::class)
             ->hourly();
    $schedule->command(\Sicaboy\LaravelSecurity\Console\Commands\LockoutInactiveAccounts::class)
             ->hourly();
    ...
}

php artisan vendor:publish --provider="Sicaboy\LaravelSecurity\LaravelSecurityServiceProvider"

app/config/laravel-security.php
resources/views/vendor/laravel-security/
resources/lang/en/laravel-security.php