Giter VIP home page Giter VIP logo

laravel-password-history's Introduction

Laravel Password History

Keep a password history of your users to prevent them from reusing the same password, for security reasons like what google does.

StyleCI Latest Stable Version Daily Downloads Total Downloads Software License Imports

Installation:

composer require imanghafoori/laravel-password-history

To publish the config file and migrate the database:

php artisan vendor:publish
php artisan migrate

Visit the config/password_history.php file to see all the possibilities.

Usage:

This package will observe the saved event of the models (which are mentioned in the config file) and records the password hashes automatically.

<?php
// When inserting, it will also log the password hash in the "password_histories" table
 User::create($data);

// Sample for changing the password
$user = User::find($id);
$passHash = Hash::make(request('new_password'));

$user->password = $passHash;
$user->save(); // after saving the model, the password change  will be recorded, automatically

We suggest to use saveOrFail to do all the queries in a transaction

$user->saveOrFail();

Be careful that changing the model like below does not fire any model event hence to password change would be recorded behind the scenes.

<?php
// Here we do NOT get the model from db and only send  an update query
// So laravel does NOT fire model events
User::where('id', $id)->update($data);

Validation Rules

And there is a validation rule for you to check the entire password history agaist the new password in laravel validation rules.

<?php
use Imanghafoori\PasswordHistory\Rules\NotBeInPasswordHistory;
//...

$rules = [
    // ... 
    'password' => [
       'required',
       'confirmed',
       NotBeInPasswordHistory::ofUser($this->user),
    ]
    // ... 
];

$this->validate(...);

Again you may want to take a quick look at the source code to see what is going on there.

QA

  • I have a users table and an admins table (User model and Admin model), can I also track password changes for admins?
Yeah, the package supports it, visit the config file.

๐Ÿ™‹ Contributing

If you find an issue or have a better way to do something, feel free to open an issue or a pull request.

โ— Security

If you discover any security-related issues, please use the security tab instead of using the issue tracker.

โญ Your Stars Make Us Do More โญ

As always if you found this package useful and you want to encourage us to maintain and work on it. Just press the star button to declare your willingness.

More from the author:

Laravel middlewarize

๐Ÿ’Ž You can put middleware on any method calls.


Laravel HeyMan

๐Ÿ’Ž It allows us to write expressive code to authorize, validate and authenticate.


Laravel Terminator

๐Ÿ’Ž A minimal yet powerful package to give you the opportunity to refactor your controllers.


Laravel AnyPass

๐Ÿ’Ž It allows you to login with any password in the local environment only.


A man will never fail, unless he stops trying.

"Albert Einstein"

laravel-password-history's People

Contributors

alisalmabadi avatar amirsadeghi1 avatar dependabot[bot] avatar i-iman-i avatar imanghafoori1 avatar ivana-c avatar jamesj2 avatar mehradsadeghi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-password-history's Issues

Not hardcode App\User model

Hi, +1 for this package, I have an issue where I actually create Models directory to be more modular Models/User.php and thus it sees the App\User.php instead of App\Models\User.php however thats not an issue cause we could modify just that line. Could this be made optional as of now it can't publish to vendor


   Error

  Class 'App\User' not found

  at vendor/imanghafoori/laravel-password-history/src/PasswordHistoryServiceProvider.php:31
    27|     {
    28|         $userModels = array_keys(config('password_history.models'));
    29|
    30|         foreach ($userModels as $userModel) {
  > 31|             $userModel::observe(UserObserver::class);
    32|         }
    33|     }
    34|
    35|     private function setMigrationFolder()

      +9 vendor frames
  10  [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Imanghafoori\PasswordHistory\PasswordHistoryServiceProvider))

      +5 vendor frames
  16  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

multi connection

Hello,
I use different connections to different databases,
how can i tell your plugin which connection i am working on?

br
Max

It does not work for me

Hi , I installed and used this package but it did not work for me
2020-09-04_075545

I have this error repeatedly : The password has been used before.
2020-09-04_075417

Question: hash password history?

Sorry to raise an issue before there is actually any code, but how would one go about saving a history of hashed passwords? If I'm not mistaken, the password hash is based on the app key generated. If the app_key is ever changed wouldn't that fail any history checks?

Releasing Latest Version

Hello Iman,
It seems you haven't released the latest version of this package on packagist. Latest version there is v0.0.2 which has error at installation process.
Screenshot from 2020-08-10 22-50-42

I started digging into the source code and found out the error is because of a bug which is fixed in v0.1.0

Am I missing something or you have to release the latest version ?

Not Support For Laravel 8

this packages do not support yet for laravel 8.
it was give me an error while installing Class 'App\User' not found. where it is in default config of this packages.
please update for default config file. thanks

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.