Coder Social home page Coder Social logo

laravel-auth-log's Introduction

Laravel Auth Log

Latest Stable Version MIT Licensed Quality Score Total Downloads GitHub Workflow Status

The laravel-auth-log package will log all the default Laravel authentication events (Login, Attempting, Lockout, etc.) to your database. In the config file you can select the events that you would like to log. It will save the event name, email, user id, ip address and user agent to the database. No other configurations are required. This package could be useful for tracking unwanted activity in your Laravel application.

Requirements

  • Laravel 8.x or 9.x

Laravel support

Version Release
9.x 1.1
8.x 1.0

Installation

1. Install the package via composer

composer require label84/laravel-auth-log

2. Publish the config file and migration

php artisan vendor:publish --provider="Label84\AuthLog\AuthLogServiceProvider" --tag="config"
php artisan vendor:publish --provider="Label84\AuthLog\AuthLogServiceProvider" --tag="migrations"

3. Run migration

php artisan migrate

Usage

In the config file config/authlog.php you can (un)comment the events that you'd like to log to your database.

// config/authlog.php

return [
    // ...
    'events' => [
        \Illuminate\Auth\Events\Attempting::class,
        // \Illuminate\Auth\Events\Authenticated::class,
        \Illuminate\Auth\Events\Failed::class,
        \Illuminate\Auth\Events\Lockout::class,
        \Illuminate\Auth\Events\Login::class,
        \Illuminate\Auth\Events\Logout::class,
        \Illuminate\Auth\Events\OtherDeviceLogout::class,
        \Illuminate\Auth\Events\PasswordReset::class,
        \Illuminate\Auth\Events\Registered::class,
        \Illuminate\Auth\Events\Verified::class,
    ],
];

In the same file you can can also change the database connection and table name.

Enable/disable logging

You can add the AUTH_LOG_ENABLED= to your .env file to enable/disable the logging.

// .env

AUTH_LOG_ENABLED=true

Table format example

id event_name email user_id ip_address user_agent context created_at
1 Attempting [email protected] 127.0.0.1 Mozilla/5.0 (Windows NT 10.0... 2022-01-10 00:00:00
2 Login 1 127.0.0.1 Mozilla/5.0 (Windows NT 10.0... 2022-01-10 00:00:00

Tests

./vendor/bin/phpstan analyse
./vendor/bin/phpunit

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.