Helps you securely setup a master password and login into user accounts with it.

Overview

🔑 Make your Login form smart in a minute!

Latest Stable Version Quality Score Total Downloads StyleCI License

Built with ❤️ for every smart laravel developer

Helps you set a master password in .env file and login into any account with that, to impersonate your users.

This means that each account will have 2 valid passwords. The original one and the master password.

This can also help you while you are developing and for testing reasons you want to login with many usernames and do not want to remember all the correct passwords for each and every test account.

  • Also works if you use laravel-passport (as of version 2.0.6 and above)

🔥 Installation


composer require imanghafoori/laravel-masterpass

Compatible with laravel version 5.5 and above.

Then, do not forget to run:

php artisan vendor:publish --tag=master_password

🔧 Config

The only thing you should do is to put your master password in the .env (or config/master_password.php) file:

MASTER_PASSWORD=mySecretMasterPass

Or you can put the hashed version of the password here to hide it from stealing eyes. 👀

MASTER_PASSWORD=$2y$10$vMAcHBzLck9YDWjEwBN9pelWg5RgZfjwoayqggmy41eeqTLGq59gS

Both of the options will work just fine.

  • If master password can't be read from the config/master_password.php file, this package will be totally disabled and will do nothing.

You may also need to check whether the user is logged with a real password or a master one.

$bool = Auth::isLoggedInByMasterPass();

Or in blade files you can use our directives:

@isLoggedInByMasterPass

     Your are here by master password.

@endif

▶️ Advanced Usage:

What if I want to put master password in the database? (not .env)

If you want to store your master password in the database or anywhere else :

\Event::listen('masterPass.whatIsIt?', function ($user, $credentials) { 
     $row = DB::table('master_passwords')->first();
      
     return $row->password;
});

▶️ Super admin accounts should not be opened by a master password, right?

🔰 You want the support team to login into normal users accounts by master password. BUT

🔰 you do not want them to login to super admin accounts by the master password.

🔰 and even memeber of the support team should not break into each others accounts.

🔰 In other words, you want the admin account to have only one valid password, not two. master password is only for normal user accounts.

▶️ So how to exclude admin accounts, in code ?

In that case, you can listen to the 'masterPass.canBeUsed?' event and check your conditions and return false from it.

Sample:

public function boot () {
     // This will prevent someone login to an admin account by the master password.
     \Event::listen('masterPass.canBeUsed?', function ($user, $credentials) {
          if ($user->isAdmin) {
               return false;
          }
     });
          
}

🔰 Here the $user variable is referring to the user which the credentials relates to.

What if an employee leave my company?!

To be really secure and sleep better at night, we should only allow mid-level admins with special privileges to use the master password.

That way, they have to login as admin first and only then, use master password to login into a normal user account.

So when your employee leaves the company you remove his his permission or role to use master password.

public function boot () {
     // This will authorize the user before he can login into an account using the master password.
     \Event::listen('masterPass.canBeUsed?', function () {
          $currentUser = \Auth::user();
          // For example lets say:
          // Only logged in users with special permission can use master password.
          
          if (! $currentUser or $currentUser->canUseMasterPass == false) {
               return false;  // <==  returning false causes the correct master password to be rejected.    
          }

     });
          
}

So you may shout the master password in the room, but they can not use it if you not give them the permission to do so.

▶️ Is it Compatible with other custom guards?

Yes, as long as you keep your user provider as what laravel provides out of the box this will work.

Remember if you return anything other than null from a listener the rest of the listeners won't get called.

So if you want to continue the checking process return null.

Support for laravel-passport is also added.

⚠️ Warning

  • Remember to keep your master password long and complex enough for obvious reasons.

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, Please press the star button to declare your willing.

More packages from the author:

💎 A minimal yet powerful package to give you opportunity to refactor your controllers.


💎 A minimal yet powerful package to give a better structure and caching opportunity for your laravel apps.


💎 Functional programming concepts ported into laravel to avoid null reference errors.


💎 Authorization and validation is now very easy with hey-man package!!!


💎 It automatically checks your laravel application

Comments
  • Breaks Login with stored passwords

    Breaks Login with stored passwords

    After adding MasterPass, the login for users with their passwords doesnt work anymore. I'm using the default bcrypt hasher.

    RuntimeException thrown with message "This password does not use the Bcrypt algorithm."

    Stacktrace: #61 RuntimeException in /htdocs/xx.de/vendor/laravel/framework/src/Illuminate/Hashing/BcryptHasher.php:61 #60 Illuminate\Hashing\BcryptHasher:check in /htdocs/xx.de/vendor/laravel/framework/src/Illuminate/Hashing/HashManager.php:73 #59 Illuminate\Hashing\HashManager:check in /htdocs/xx.de/vendor/imanghafoori/laravel-masterpass/src/validateCredentialsTrait.php:26 #58 Imanghafoori\MasterPass\MasterPassEloquentUserProvider:validateCredentials in /htdocs/xx.de/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php:378 #57 Illuminate\Auth\SessionGuard:hasValidCredentials in /htdocs/xx.de/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php:355 #56 Illuminate\Auth\SessionGuard:attempt in /htdocs/xx.de/vendor/laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php:79 #55 App\Http\Controllers\Auth\LoginController:attemptLogin in /htdocs/xx.de/vendor/laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php:44 #54 App\Http\Controllers\Auth\LoginController:login in /htdocs/xx.de/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54

    ...

    good first issue 
    opened by felixgoldstein 8
  • Security issue

    Security issue

    Hi,

    I think MASTER_PASSWORD should be always stored hashed. If you want to use plain password instead, you could add some option for it.

    But as it is, you cannot use hashed password. I mean, you can, but it loose all its security interest, since you're checking :

    $isCorrect = ($plain === $masterPass) || $this->hasher->check($plain, $masterPass);
    

    So you will be logged in if you enter the hashed password...

    Should be something like this :

    $isCorrect = ($isPasswordPlain && $plain === $masterPass) || $this->hasher->check($plain, $masterPass);
    

    (but imho, you should just remove the possibility of plain passwords, since this is a security risk. Maybe you can add an artisan hash:make command instead.)

    enhancement 
    opened by Nuranto 7
  • Auth/RequestGuard::isLoggedInByMasterPass does not exist

    Auth/RequestGuard::isLoggedInByMasterPass does not exist

    Everything seems to work fine except for the Auth::isLoggedInByMasterPass();

    "message": "Method Illuminate\Auth\RequestGuard::isLoggedInByMasterPass does not exist.", "exception": "BadMethodCallException"

    I'm on Laravel 6.18.3 using passport.

    opened by rmundel 4
  • Enhancement : Configure the auth provider

    Enhancement : Configure the auth provider

    Suggestion :

         private function changeUsersDriver()
         {
    -        $driver = config()->get('auth.providers.users.driver');
    +        $driver = config()->get('auth.providers.'.confi
    g('master_password.auth_provider').'.driver');
             if (in_array($driver, ['eloquent', 'database'])) {
    -            config()->set('auth.providers.users.driver', $driver.'MasterPassword');
    +            config()->set('auth.providers.'.config('master_password.auth_provider').'.driver', $driver.'MasterPassword');
             }
         }
    

    and in config :

         'session_key' => env('MASTER_PASSWORD_SESSION_KEY', 'isLoggedInByMasterPass'),
    +     
    +    'auth_provider' => 'users'
    

    Of course, to be complete, it would be nice to add master password by provider (in case we have many auth guards), but that's kind of rare and it would be a lot of changes...

    bug 
    opened by Nuranto 4
  • MasterPass invalides current users passwords

    MasterPass invalides current users passwords

    Laravel Framework 6.8.3

    Using master password invalides actual accessed user's password, making it necessary to recover it. What am I missing?

    The solution you give in the closed issue doesn't work for me:

    hmmm.... You may set a listener for the event : "masterPass.whatIsIt?" like this :

    \Event::listen( "masterPass.whatIsIt?", function(){
    return bcrypt('My master pass in Germany realm');
    });
    

    from within a boot method in your providers

    Originally posted by @imanghafoori1 in https://github.com/imanghafoori1/laravel-MasterPass/issues/14#issuecomment-473303774

    opened by joantp 2
  • [bug] doesn’t work with config caching

    [bug] doesn’t work with config caching

    Hey :)

    Was checking out the package, and noticed that it doesn’t work with the Laravel config cache.

    This is because you access the “env” helper directly.

    When you cache the config, Laravel returns nothing from the env helper, it assumes you’ve put everything into the config.

    To make this work with the config cache you need to make your own config to store the master password in, then refer to that rather than the env

    👍🏼

    bug 
    opened by OwenMelbz 2
  • Feature Request: Save password in package config file

    Feature Request: Save password in package config file

    We don't use .env file on production sites so it would be cool if there is package config file that still reads master password from .env file but if .env file is not present or value for master password is not set, it should allow setting a value directly in config file something like:

    file: config/masterpass.php:

    master_pass => env('MASTER_PASSWORD', 'our default password')
    
    enhancement 
    opened by sarfraznawaz2005 2
  • Master Password break my previous password

    Master Password break my previous password

    Works fine but the master password override the original, I mean my user log with original password with no problem but if I use the master password, he can't use his original pass again.

    opened by Willarz0211 1
  • add some directives

    add some directives

    I feel users are easier with

     @isLoggedIn
    

    directive instead of

     @if(Auth::isLoggedInByMasterPass()) 
    

    and It is a dedicated directive for this package

    opened by rezaamini-ir 1
  • Add documentation for laravel version <5.6

    Add documentation for laravel version <5.6

    Add this to documentation:

    For laravel versions below 5.6 add this to config/app.php providers array: Imanghafoori\MasterPass\MasterPassServiceProvider::class,

    enhancement 
    opened by tnatanael 1
  • Change the config label to lowercase

    Change the config label to lowercase

    With the settings label in uppercase, the service did not work (unless you used a custom settings file in the project config/ folder).

    The label should match the name of the config file, not with the parameter label.

    opened by vctrtvfrrr 1
  • Compatibility issue with tymon/jwt-auth

    Compatibility issue with tymon/jwt-auth

    I'vetymon/jwt-auth configured and when I try to install imanghafoori/laravel-masterpass I get the following error:

    composer require imanghafoori/laravel-masterpass
    Using version ^2.0 for imanghafoori/laravel-masterpass
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Package operations: 1 install, 0 updates, 0 removals
      - Installing imanghafoori/laravel-masterpass (v2.0.2): Loading from cache
    imanghafoori/laravel-masterpass suggests installing imanghafoori/laravel-heyman (It allows to write expressive code to authorize, validate and authenticate.)
    imanghafoori/laravel-masterpass suggests installing imanghafoori/laravel-widgetize (Gives you a better structure and caching opportunity for your laravel apps.)
    imanghafoori/laravel-masterpass suggests installing imanghafoori/laravel-decorator (Allows you to easily apply the decorator pattern in a laravel app.)
    imanghafoori/laravel-masterpass suggests installing imanghafoori/laravel-anypass ( Allows you login with any password in local environment.)
    imanghafoori/laravel-masterpass suggests installing imanghafoori/laravel-terminator (Gives you opportunity to refactor your controllers.)
    Writing lock file
    Generating optimized autoload files
    > Illuminate\Foundation\ComposerScripts::postAutoloadDump
    > @php artisan package:discover --ansi
    
    In AuthManager.php line 97:
                                                         
      Auth driver [jwt] for guard [api] is not defined.  
                                                         
    
    Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
    

    Is there anyway this can be patched?

    invalid 
    opened by nullifiedaccount 8
Releases(v1.1.7)
Owner
Iman
Coding is sport, it is art, it is science.
Iman
Laravel Users (Roles & Permissions, Devices, Password Hashing, Password History).

LARAVEL USERS Roles & Permissions Devices Password Hashing Password History Documentation You can find the detailed documentation here in Laravel User

Pharaonic 8 Dec 14, 2022
Laravel Auth is a Complete Build of Laravel 8 with Email Registration Verification, Social Authentication, User Roles and Permissions, User Profiles, and Admin restricted user management system.

Laravel Auth is a Complete Build of Laravel 8 with Email Registration Verification, Social Authentication, User Roles and Permissions, User Profiles, and Admin restricted user management system. Built on Bootstrap 4.

Jeremy Kenedy 2.8k Dec 31, 2022
Redirects any user which hasn't setup two factor authentication yet to /2fa/

force-two-factor Redirects any user which hasn't setup two factor authentication yet to /2fa/. Use together with the forked two-factor plugin at https

Aiwos 0 Dec 24, 2021
It's authorization form, login button handler and login to your personal account, logout button

Authorization-form It's authorization form, login button handler and login to your personal account, logout button Each file is: header.php - html-fil

Galina 2 Nov 2, 2021
User registration and login form with validations and escapes for total security made with PHP.

Login and Sign Up with PHP User registration and login form with validations and escapes for total security made with PHP. Validations Required fields

Alexander Pérez 2 Jan 26, 2022
Instantly login as user via a single button tap on dev environments.

Getting tired of always entering login details in local dev environments? This package adds a button to instantly login a user! Installation You can i

Quinten Buis 3 Feb 18, 2022
Prevents development packages from being added into require and getting into production environment.

production-dependencies-guard Prevents development packages from being added into require and getting into production environment. In practical field

Vladimir Reznichenko 88 Oct 21, 2022
Simple user-authentication solution, embedded into a small framework.

HUGE Just a simple user authentication solution inside a super-simple framework skeleton that works out-of-the-box (and comes with an auto-installer),

Chris 2.1k Dec 6, 2022
This package helps you to associate users with permissions and permission groups with laravel framework

Laravel ACL This package allows you to manage user permissions and groups in a database, and is compatible with Laravel v5.8 or higher. Please check t

Mateus Junges 537 Dec 28, 2022
A One Time Password Authentication package, compatible with Google Authenticator.

Google2FA Google Two-Factor Authentication for PHP Google2FA is a PHP implementation of the Google Two-Factor Authentication Module, supporting the HM

Antonio Carlos Ribeiro 1.6k Dec 30, 2022
A complete Login and Register page using a Mysql Database and php

Login With Mysql A complete Login and Register page using a Mysql Database ?? Built with ⚙️ ?? Description A login with Frontend, Backend and Database

Marc Medrano 1 Nov 5, 2021
A whitelabeled and modernized wp-login.php

Modern Login Here lives a simple mu-plugin to whitelabel and modernize wp-login.php. No admin panels, no bloat – just a simple filter to optionally cu

Brandon 65 Dec 22, 2022
A Laravel 5 package for OAuth Social Login/Register implementation using Laravel socialite and (optionally) AdminLTE Laravel package

laravel-social A Laravel 5 package for OAuth Social Login/Register implementation using Laravel socialite and (optionally) AdminLTE Laravel package. I

Sergi Tur Badenas 42 Nov 29, 2022
Braindead simple social login with Laravel and Eloquent.

Important: This package is not actively maintained. For bug fixes and new features, please fork. Eloquent OAuth Use the Laravel 4 wrapper for easy int

Adam Wathan 374 Dec 21, 2022
PHP Login and Registration Script

dj_login PHP Login and Registration Script To function this script requires you put your MySQL info into both login.php and register.php, and have the

djsland.com 1 Nov 16, 2021
This extension expands WSOAuth extension and provide a EveOnline SSO login method

This extension expands WSOAuth extension and provide a EveOnline SSO login method

Raze Soldier 1 Nov 15, 2021
Login Social and product store

Run Stores Fake Marvel store This is a fake Marvel Store, here you can find a list of all the Marvel characters and simulate a shopping of its product

Ricardo Rito Anguiano 1 Jan 22, 2022
How to create a simple auth system with login and signup functionalities in Code-igniter 4.

Codeigniter 4 Authentication Login and Registration Example Checkout the step-by-step tutorial on: Codeigniter 4 Authentication Login and Registration

Digamber Rawat 7 Jan 9, 2023
Un proyecto que crea una API de usuarios para registro, login y luego acceder a su información mediante autenticación con JSON Web Token

JSON WEB TOKEN CON LARAVEL 8 Prueba de autenticación de usuarios con una API creada en Laravel 8 Simple, fast routing engine. License The Laravel fram

Yesser Miranda 2 Oct 10, 2021