RequirePin is a Laravel package that provides middleware to enforce PIN confirmation and validation before processing requests to specified routes, adding an extra layer of security to your application.
- Requirements
- Installation
- Configuration
- Usage
- Customization
- Reserved Keys for Payload
- To Display Return Payload Within Blade
- Security Considerations
- Contributing
- License
- PHP 7.3 or higher
- Laravel 8 or higher
To install the package, run the following command:
composer require ikechukwukalu/requirepinAfter installation, publish the migration files:
php artisan vendor:publish --tag=rp-migrationsThen, run the migrations:
php artisan migrateConfigure your .env file to use Redis for queue management:
REDIS_CLIENT=predis
QUEUE_CONNECTION=redisFinally, start the queue worker:
php artisan queue:workRequirePin uses Redis to manage PIN confirmation queues efficiently. Ensure that your Redis server is properly configured and running.
To enforce PIN confirmation on specific routes, apply the require.pin middleware to those routes or route groups. For example:
Route::middleware(['require.pin'])->group(function () {
// Protected routes
});The package provides the following routes:
API Routes:
POST api/change/pin: Endpoint to change the user's PIN.POST api/pin/required/{uuid}: Endpoint to confirm the PIN for a specific request.
Web Routes:
POST change/pin: Endpoint to change the user's PIN.POST pin/required/{uuid}: Endpoint to confirm the PIN for a specific request.GET change/pin: Page to display the form for changing the PIN.GET pin/required/{uuid?}: Page to display the form for PIN confirmation.
Note: To receive JSON responses, add the 'Accept: application/json' header to your requests.
The following keys are reserved for use within the payload:
uuid- Unique identifier for the PIN request.pin- The PIN value submitted by the user.expires- Expiration time for the PIN request.signature- Timestamp indicating when the PIN was verified.return_payloadpin_validation
Ensure these keys are not overridden when handling the payload.
To display the returned payload values within a Blade template, use:
@if (session('return_payload'))
@php
[$status, $status_code, $data] = json_decode(session('return_payload'), true);
@endphp
<div class="alert alert-{!! $status === 'fail' ? 'danger' : 'success' !!} m-5 text-center">
{!! $data['message'] !!}
</div>
@endifYou can customize this based on your application's needs.
- PIN Policies: Ensure that your application enforces strong PIN policies, such as minimum length and complexity requirements.
- Rate Limiting: Implement rate limiting on PIN confirmation endpoints to prevent brute-force attacks.
- Secure Storage: Store PINs securely using appropriate hashing algorithms.
Contributions are welcome! Please read the contribution guidelines before submitting a pull request.
This package is open-sourced software licensed under the MIT license.