Download the PHP package nagibmahfuj/laravel-security-policies without Composer

On this page you can find all versions of the php package nagibmahfuj/laravel-security-policies. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-security-policies

Laravel Security Policies

A Laravel package that enforces organization-grade security policies:

Supports Laravel 8/9/10/11/12 and PHP 8.0+.

Features

Installation

Install via Composer:

Then dump autoload:

If auto-discovery is not active, register the service provider in config/app.php:

Clear caches if needed:

Publish config

Publish config:

This will create a config/security-policies.php file with default values. You can modify these values as per your requirements. Check below for the configuration options.

Configuration

config/security-policies.php options (grouped):

Session

Key Type Default Description
session.idle_timeout_minutes integer 30 Minutes of inactivity before forcing logout.
session.redirect_on_idle_to string (route name) login Route to redirect to after idle timeout.
session.last_activity_store string session Where to store last activity timestamp: 'session' or 'database'

MFA

Key Type Default Description
mfa.enabled bool true Enable/disable MFA enforcement.
mfa.mode string trusted_only 'trusted_only' or 'grace_or_trusted' (see below).
mfa.redirect_when_not_needed string '/' URL or route name to redirect to when MFA is not required (user already verified).
mfa.grace_days_after_login integer 30 Require MFA again if last verification is older than X days.
mfa.otp_length integer 6 Length of the OTP code.
mfa.otp_ttl_minutes integer 10 OTP validity window in minutes.
mfa.max_attempts integer 5 Max verify attempts before requiring a new OTP.
mfa.throttle_per_minute integer 5 Intended per-minute throttle (implement rate limiting as needed).
mfa.device_remember_days integer 60 Days to trust a device when “remember this device” is selected.
mfa.remember_device_cookie string mfa_trusted_device Cookie name for trusted device fingerprint.
mfa.device_session_control string multiple Control device access: 'single' or 'multiple'.
mfa.single_device_action string logout_previous Action when single device mode and new login detected: 'logout_previous' or 'prevent_new'.

MFA Modes

Device Session Control

When mfa.device_session_control is set to 'single', users can only be logged in on one device at a time. This feature leverages the existing trusted_devices table to track active sessions.

Device fingerprinting uses IP address, User-Agent, Accept-Language, and Accept headers to uniquely identify devices. The system automatically tracks device activity and updates last seen timestamps.

Password

Key Type Default Description
password.min_length integer 12 Minimum password length.
password.min_digits integer 1 Minimum digits required.
password.min_symbols integer 1 Minimum symbols required.
password.min_lowercase integer 1 Minimum lowercase letters required.
password.min_uppercase integer 1 Minimum uppercase letters required.
password.allowed_symbols string !@#$%^&*()_+-={}[]:;'"<>,.?/\\|~ Allowed symbol set counted by StrongPassword and used to reject disallowed characters.
password.expire_days integer 90 Force password change after X days.
password.history integer 5 Disallow reuse of last X passwords.
password.require_history bool false If true, user must have at least one password history entry; otherwise redirected to change page.
password.redirect_on_expired_to string (route name) password.request Route to redirect to when password is expired or when history is required but missing.

User Columns

Key Type Default Description
user_columns.last_mfa_at string last_mfa_at User model column that stores when MFA was last completed.
user_columns.password_changed_at string password_changed_at User model column that stores when password was last changed.
user_columns.last_activity_at string last_active_at User model column that stores the last activity timestamp when using database storage.

Publish migrations:

Register middleware aliases in app/Http/Kernel.php

If aliases are not already present, add these to $middlewareAliases:

Add Middlewares

The package registers aliases for convenience. In your route groups, add:

The idle timeout is typically applied to the web group:

Alternatively, use the alias security.idle in specific groups.

Use the Validation Rules

In Laravel 9+, Apply these rules where users set or change passwords:

For Laravel 8 and below, Apply these rules where users set or change passwords:

MFA Routes and Views

The package provides routes:

Views are loaded from the package and can be published/overridden:

Database Schema

Enabling Database Storage for Last Activity

To use database storage for last activity tracking:

  1. Ensure your users table has a timestamp column for last activity (default: last_active_at). The published migration will add this if needed.
  2. Set the following in config/security-policies.php:

  3. The middleware will now track last activity in the database instead of the session.

Events & Listeners

If you are using a custom password change flow, you can trigger the event manually after updating the password:

Security Considerations

Testing

License

MIT License. See LICENSE.


All versions of laravel-security-policies with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/support Version ^8|^9|^10|^11|^12
illuminate/auth Version ^8|^9|^10|^11|^12
illuminate/notifications Version ^8|^9|^10|^11|^12
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nagibmahfuj/laravel-security-policies contains the following files

Loading the files please wait ...