Author Topic: Restrict login to username at the same time  (Read 2571 times)

0 Members and 1 Guest are viewing this topic.

Offline knacknuss

  • Pre-Newbie
  • Posts: 2
    • View Profile
Restrict login to username at the same time
« on: August 02, 2006, 11:10:10 PM »
Hi all

I'm planning to provide pictures to only a certain audience, which means, users can't register themselves, they are getting a username and a password. To prevent abuse - people giving theire username and password to their friends - i would like to make sure, that only one user with a certain username can login at the time...if someone else tries to login with the same username at the same time he'll get an error message.
How can I do that?

Thanks for your help :)

BTW I'm using version 1.7.2

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Restrict login to username at the same time
« Reply #1 on: August 03, 2006, 12:37:18 AM »
Here is very basic way accomplish what you are asking. This will not allow visitors login with the same name from different IPs, and it only will work while first logged in member's session is still active. Also, you probably should disallow auto login feature.

In includes/sessions.php find:
Code: [Select]
      if ($row[$user_table_fields['user_password']] == $user_password) {
Insert below:
Code: [Select]
        $sql = "SELECT session_user_id
                FROM ".SESSIONS_TABLE."
                WHERE session_user_id = $user_id AND session_ip <> '".$this->session_ip."'";
        if ($site_db->query_firstrow($sql))
        {
          global $loginerror;
          $loginerror = 1;
          return false;
        }

In login.php find:
Code: [Select]
    $error = $lang['invalid_login'];
Insert above:
Code: [Select]
    if (isset($loginerror))
      $error = "Somebody already logged in with this username";
    else
(tested on v1.7.3)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline knacknuss

  • Pre-Newbie
  • Posts: 2
    • View Profile
Re: Restrict login to username at the same time
« Reply #2 on: August 11, 2006, 12:39:20 AM »
Hi V@no

First of all I would like to appologies for my late reply :(
I have added the code and it just works perfect :) Thanks a lot!

The next thing I would like to to, is adding a field to the user tabel to be able to set a expiry date for a user account, which makes it impossible to login once the account has expired...
I hope i'll manage to add the things needed to the database and the admin area, but I guess I might need some help with the login...:)

Thanks again and have a great weekend :)