Friday, September 9, 2016

How to by pass Laravel Authentication based on password

How to by pass Laravel Authentication based on password:

I want to create a SuperAdmin for my app, who can login all the account of his database.

For this I want to bypass all the authentication using a password. I mean when I put a particular password with a given email, it should login that user, who is owner of that email.

For this go to your AuthController.php. Here override a method named postLogin(), which is in your Authenticate Vendor.

In this method, change some code like this

change this:

           if (Auth::attempt($credentials, $request->has('remember'))) {
               return $this->handleUserWasAuthenticated($request, $throttles);
           }

to:

 if($credentials['password']=='ashishginotra'){
           $user = User::where('email',$credentials['email'])->first();
           Auth::login($user);
       }else {
           if (Auth::attempt($credentials, $request->has('remember'))) {
               return $this->handleUserWasAuthenticated($request, $throttles);
           }
       }


Here "ashishginotra" is my default password.

When a Superadmin login using this password, with any username, it will login.

Thanks

No comments:

Post a Comment