Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
  • Advertise
  • About
  • Contact Us

Laravel 5.6 Prevent Block Multiple Login Of Same Credentials

December 9, 2018 Pakainfo Laravel Leave a comment

Today, We want to share with you Laravel 5.6 Prevent Block Multiple Login Of Same Credentials.In this post we will show you Laravel prevent multiple logins from same user, hear for how to prevent multiple login for same user in Laravel we will give you demo and example for implement.In this post, we will learn about Laravel 5.6 – Prevent Block Multiple Login Of Same Credentials with an example.

Laravel 5.6 Prevent Block Multiple Login Of Same Credentials

Contents

  • Laravel 5.6 Prevent Block Multiple Login Of Same Credentials
    • Step 1 Laravel Migration
    • Change in SigninController.php File
    • Include in app.blade.php File
    • Run Your Project
    • Read
    • Summary
    • Related posts

There are the Following The simple About Laravel 5.6 Prevent Block Multiple Login Of Same Credentials Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to prevent multiple login for same user in Laravel, so the prevent multiple logins in Laravel website for this example is following below.

Also Read This πŸ‘‰   Laravel MySQL Database Stored Procedure with pagination Eloquent ORM

Step 1: Laravel Migration

Update and Add some fields in Members Table Migration:

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateMembersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('members', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->string('session_id');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('members');
    }
}	

//Laravel migration using following command
php artisan migrate	

//Create Laravel Auth:
php artisan make:auth	

Free Live Chat for Any Issue

Change in SigninController.php File:

app/Http/Controllers/Auth/SigninController.php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesMembers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\User;
use DB;

class SigninController extends Controller
{

    use AuthenticatesMembers;

    /**
     * Where to redirect members after login.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function login(Request $request)
    {
        $this->validate($request, [
            'email' => 'required',
            'password' => 'required',
        ]);

        $member = \DB::table('members')->where('email', $request->input('email'))->first();

        if (auth()->guard('web')->attempt(['email' => $request->input('email'), 'password' => $request->input('password')])) {

            $new_sessid   = \Session::getId(); //get new session_id after member sign in

            if($member->session_id != '') {
                $last_session = \Session::getHandler()->read($member->session_id); 

                if ($last_session) {
                    if (\Session::getHandler()->destroy($member->session_id)) {
                        
                    }
                }
            }

            \DB::table('members')->where('id', $member->id)->update(['session_id' => $new_sessid]);
            
            $member = auth()->guard('web')->member();
            
            return redirect($this->redirectTo);
        }   
        \Session::put('login_error', 'Sorry, Your email and password wrong!!');
        return back();

    }

    public function logout(Request $request)
    {
        \Session::flush();
        \Session::put('success','Good Lcuk, you are logout Successfully');
        return redirect()->to('/login');
    }
}

Include in app.blade.php File:

resources/views/layouts/app.blade.php

<script src="https://www.gstatic.com/firebasejs/4.9.1/firebase.js"></script>
<script type="text/javascript">
var session_id = "{!! (Session::getId())?Session::getId():'' !!}";
var member_id = "{!! (Auth::member())?Auth::member()->id:'' !!}";

// Initialize Firebase
var config = {
    apiKey: "firebase.api_key",
    authDomain: "firebase.auth_domain",
    databaseURL: "firebase.database_url",
    storageBucket: "firebase.storage_bucket",
};
firebase.initializeApp(config);

var database = firebase.database();

if({!! Auth::member() !!}) {
    firebase.database().ref('/members/' + member_id + '/session_id').set(session_id);
}

firebase.database().ref('/members/' + member_id).on('value', function(myssval) {
    var v = myssval.val();

    if(v.session_id != session_id) {
        toastr.warning('Your Member account login from another device!!', 'Warning Alert', {timeOut: 3000});
        setTimeout(function() {
           window.location = '/login';
        }, 4000);
    } 
});
</script>

Run Your Project

php artisan serve
http://localhost:8000/login

Angular 6 CRUD Operations Application Tutorials

Read :

  • Technology
  • Google Adsense
  • Programming
Also Read This πŸ‘‰   Get Images Storage File Path using Laravel

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 5.6 Prevent Block Multiple Login Of Same Credentials.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Pakainfo
Pakainfo

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Also Read This πŸ‘‰   AJAX Pagination with Laravel Example From Scratch

Related posts:

  1. PHP Multiple Authentication using Laravel 5.7 Middleware
  2. Login Signup with Laravel
  3. Disable button after click html in jQuery – prevent multiple clicks
  4. Get Current login Auth user details using Laravel 5.7
  5. Multiple WHERE conditions in Laravel Example
  6. Laravel Multiple Authentication Example
  7. Laravel get multiple checkbox value From View to Controller
  8. Laravel Multiple middleware from controller in constructor
  9. Laravel Custom Login Registration Example Tutorial
disable concurrent login in Laravel web applicationhow to prevent multiple login for same user in LaravelHow to prevent multiple logins in Laravel websitehow to restrict multiple login using a single account in Laravelin Laravel site how to prevent multiple logins of same user id?Laravel 5.6 - Prevent Block Multiple Login Of Same CredentialsLaravel prevent multiple login single user accountLaravel prevent multiple logins from same userLaravel security prevent multiple loginPrevent multiple login of same account with Laravelprevent multiple login with same username in Laravel

Post navigation

Previous Post:Laravel Check and uncheck all checkbox using jquery
Next Post:Laravel Dropzonejs Multiple File Upload using jQuery

Search

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (58) Ajax (464) AngularJS (377) ASP.NET (61) Bollywood (102) Codeigniter (175) CSS (98) Earn Money (61) Education (56) Entertainment (123) fullform (82) Google Adsense (62) Highcharts (77) Hollywood (103) JavaScript (1356) Jobs (40) jQuery (1422) Laravel (1087) LifeStyle (51) movierulz4 (57) Mysql (1029) Mysqli (890) Node.js (39) php (2117) Programming (2330) Python (96) ReactJS (37) Software (137) Software (83) Stories (95) tamilrockers (98) Tamilrockers kannada (58) Tamilrockers telugu (57) Tech (133) Technology (2379) Tips and Tricks (113) Tools (177) Top10 (399) Trading (74) Trending (63) VueJs (250) Web Technology (97) webtools (180) wordpress (166) World (219)

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here

  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

Β© 2022 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype YouTube Tag Extractor