4images Forum & Community

4images Issues / Ausgaben => Discussion & Troubleshooting => Topic started by: knacknuss on August 02, 2006, 11:10:10 PM

Title: Restrict login to username at the same time
Post by: knacknuss 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
Title: Re: Restrict login to username at the same time
Post by: V@no 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)
Title: Re: Restrict login to username at the same time
Post by: knacknuss 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 :)