Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 251077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:33:52+00:00 2026-05-11T21:33:52+00:00

I want to only allow one authenticated session at a time for an individual

  • 0

I want to only allow one authenticated session at a time for an individual login in my Django application. So if a user is logged into the webpage on a given IP address, and those same user credentials are used to login from a different IP address I want to do something (either logout the first user or deny access to the second user.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:33:52+00:00Added an answer on May 11, 2026 at 9:33 pm

    Not sure if this is still needed but thought I would share my solution:

    1) Install django-tracking (thankyou for that tip Van Gale Google Maps + GeoIP is amazing!)

    2) Add this middleware:

    from django.contrib.sessions.models import Session
    from tracking.models import Visitor
    from datetime import datetime
    
    class UserRestrictMiddleware(object):
        """
        Prevents more than one user logging in at once from two different IPs
        """
        def process_request(self, request):
            ip_address = request.META.get('REMOTE_ADDR','')
            try:
                last_login = request.user.last_login
            except:
                last_login = 0
            if unicode(last_login)==unicode(datetime.now())[:19]:
                previous_visitors = Visitor.objects.filter(user=request.user).exclude(ip_address=ip_address)
                for visitor in previous_visitors:
                    Session.objects.filter(session_key=visitor.session_key).delete()
                    visitor.user = None
                    visitor.save()
    

    3) Make sure it goes after the VisitorTrackingMiddleware and you should find previous logins are automatically bumped when someone new logs in 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two UIViews filled with UIButtons. I want to only allow one
i have windows media player in my application.i want to allow only the supported
We have a voting mechanism that we want to restrict to only allow one
I want to only allow editing of one column in my DataGridView, but I
I need help to only allow one decimal point to be entered into a
I have some code that I want to only allow access to by one
I want to only allow users with IE8 (not IE6, IE7) or another browser
I want to allow only English characters to be typed in my asp:TextBox (in
I want to extend Ion Auth to only allow certain email addresses to register.
What should I do if I want to allow only English alphabet to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.