Create Custom Authentication Laravel

Posted In Laravel
  • kontol-mabur-1 2 years ago
    My project recently done, But my client request to change some function like login, my client request 'suspend' feature to users, I Know its can be done with this https://laravel.com/docs/5.4/authentication#authenticating-users but I already using default authentication provide by Laravel, My question is, is podible to use this: https://laravel.com/docs/5.4/authentication#authenticating-users on my existing application?

    My project recently done, But my client request to change some function like login, my client request 'suspend' feature to users, I Know its can be done with this https://laravel.com/docs/5.4/authentication#authenticating-users but I already using default authentication provide by Laravel, My question is, is podible to use this: https://laravel.com/docs/5.4/authentication#authenticating-users on my existing application?

  • devdojo 2 years ago
    Yeah, you can totally do this with the function. You will probably want to create a new row in the database that is a `boolean` type and it can be a `0` by default. So, if the user is suspended, this will be a `1`. You could call this row `suspended` and you should be able to do something like this:
    
    ```
    <?php
    
    namespace App\Http\Controllers;
    
    use Illuminate\Support\Facades\Auth;
    
    class LoginController extends Controller
    {
        /**
         * Handle an authentication attempt.
         *
         * @return Response
         */
        public function authenticate()
        {
            if (Auth::attempt(['email' => $email, 'password' => $password])) {
                // Authentication passed...
                if(Auth::user()->suspended){
                    return redirect('account-suspended');
                }
                return redirect()->intended('dashboard');
            }
        }
    }
    ```
    
    Let me know if that helps :)
    
    Thanks.

    Yeah, you can totally do this with the function. You will probably want to create a new row in the database that is a boolean type and it can be a 0 by default. So, if the user is suspended, this will be a 1. You could call this row suspended and you should be able to do something like this:

    <?php
    
    namespace App\Http\Controllers;
    
    use Illuminate\Support\Facades\Auth;
    
    class LoginController extends Controller
    {
        /**
         * Handle an authentication attempt.
         *
         * @return Response
         */
        public function authenticate()
        {
            if (Auth::attempt(['email' => $email, 'password' => $password])) {
                // Authentication passed...
                if(Auth::user()->suspended){
                    return redirect('account-suspended');
                }
                return redirect()->intended('dashboard');
            }
        }
    }
    

    Let me know if that helps :)

    Thanks.

  • kontol-mabur-1 2 years ago
    Thanks worked perfectly! ^^

    Thanks worked perfectly! ^^

  • oliver-russell 1 year ago
    You can definitely apply [custom authentication to your Laravel application](https://www.cloudways.com/blog/laravel-login-authentication/), by editing your main controller file and adding auth in it.
    
    Once you have setup database and routes, you have to make controller. For authentication, you will have to extend MainController from the Base Controller and make three functions to show login, check the login and for logging out.

    You can definitely apply custom authentication to your Laravel application, by editing your main controller file and adding auth in it.

    Once you have setup database and routes, you have to make controller. For authentication, you will have to extend MainController from the Base Controller and make three functions to show login, check the login and for logging out.

  • xavier-alder 11 months ago
    For students the problem which is always faced is the downloading of an article and any sort of book with privacy. This is the site [https://www.paperwritingpro.com/our-services/coursework/](https://www.paperwritingpro.com/our-services/coursework/) where you can get PDF version of the files which are important for your studies.

    For students the problem which is always faced is the downloading of an article and any sort of book with privacy. This is the site https://www.paperwritingpro.com/our-services/coursework/ where you can get PDF version of the files which are important for your studies.

  • jeanclaude-mbiya 3 months ago
    Hi, i'm new in laravel and i have tried to use the laravel auth system in my app, with everything default ( routes, controllers..) please i want to know i can change or customise the verify email routes and also customize all the default auth. thanks
    

    Hi, i'm new in laravel and i have tried to use the laravel auth system in my app, with everything default ( routes, controllers..) please i want to know i can change or customise the verify email routes and also customize all the default auth. thanks

  • william-chambers 3 weeks ago
    In this case, I have a great recommendation for you when I need to find a book or any additional materials on it, such as [macbeth prophecy quote](https://freebooksummary.com/how-does-macbeth-react-to-the-witches-prophecies-20494), then I always turn to a free educational platform where I can always find the book I need or something related with her. Maybe this will help you!

    In this case, I have a great recommendation for you when I need to find a book or any additional materials on it, such as macbeth prophecy quote, then I always turn to a free educational platform where I can always find the book I need or something related with her. Maybe this will help you!

Please login or signup to leave a response.

Login

or Sign Up

Sign Up

or Login
×
Want to create your own SAAS?

I can teach you to create your own Software as a Service. Click here to learn more!

Visit SAAS Adventure!