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

Ask A Question

Stats

  • Questions 234k
  • Answers 234k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try comparing the output of childNodes.firstChild to childNodes.firstChild.nodeValue May 13, 2026 at 5:57 am
  • Editorial Team
    Editorial Team added an answer I don't see anything wrong with your code; all you… May 13, 2026 at 5:57 am
  • Editorial Team
    Editorial Team added an answer Apart from that my answer is not programming related: That's… May 13, 2026 at 5:57 am

Related Questions

I am using the Kohana framework (but I think it's irrelevant for this question)
I'm creating a tree structure that is based on an AbstractNode class. The AbstractNode
The site I am working with has a somewhat convoluted way with dealing with
I have some code that I want to only allow access to by one

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.