Prevent multiple Login with Same ID

Prevent multiple Login with Same ID

by Swanand Taware -
Number of replies: 4

Hi All,

Somehow i find out way to prevent multiple login with same id.

Below are Steps to follows:

Step 1:

Create Table in Moodle database

SELECT c.fullname Course_Name,sc.name as Assessment_Title,st.attempt Attempt, st.VALUE,FROM_UNIXTIME(st.timemodified,"%m-%d-%Y") Attempt_Date,FROM_UNIXTIME(mcc.timecompleted,"%m-%d-%Y") Completion_Date,

(CASE WHEN mcc.timecompleted IS NULL THEN 'Not Completed' ELSE 'Completed'

END) AS 'status'

FROM mdl_course_completions mcc

JOIN mdl_course AS c ON c.id=mcc.course

JOIN mdl_scorm AS sc ON sc.course=c.id

JOIN mdl_user AS u

JOIN mdl_scorm_scoes_track AS st on st.scormid = sc.id AND st.userid = u.id

============================================================================

Step 2: 

Add Below code into file lib.php of your theme directory.

function theme_klass_page_init(moodle_page $page) {


    global $DB, $CFG, $SESSION, $USER;

    $userid = $USER->id;

    $sessKey = $USER->sesskey;

    $rs = $DB->get_record_sql("SELECT count(*)AS count FROM `mdl_sessions` WHERE `userid` = '" . $userid . "'");

    echo "count===><br>";

    echo $rs->count;

    echo "<br>user id===><br>";

    echo $userid;

    if ($userid != 0) {

        if ($rs->count > 1) {

            echo "inside";//die('kasjhfskja');

            //if user login from another browser we have to logout that old user

             //$CFG->logoutredirect;

            $var =  $CFG->wwwroot."/login/logout.php?sesskey=".$sessKey;

            header( 'Location: ' . $var );

            

        }

    }

    $page->requires->jquery();

    $page->requires->jquery_plugin('migrate');

    $page->requires->js('/theme/klass/javascript/theme.js');

}

Average of ratings: -
In reply to Swanand Taware

Re: Prevent multiple Login with Same ID

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Hi,

Or you can go to "Site administration > Plugins > Authentication > Manage authentication" and specify a value for "Limit concurrent logins " (limitconcurrentlogins) wink

HTH
Séverin

Average of ratings: Useful (5)
In reply to Séverin Terrier

Re: Prevent multiple Login with Same ID

by Jody Baty -

I have enabled this setting. It worked previously but has recently stopped working on Moodle 3.1.5+ (Build: 20170316) . Are there any other settings that need to be adjusted for this to work?



In reply to Jody Baty

Re: Prevent multiple Login with Same ID

by Thanmai Gurijala -
Hi, Did you find a solution for this? Is the limit concurrent login feature working?
In reply to Jody Baty

Re: Prevent multiple Login with Same ID

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Hi,

Are you sure about that?

Don't you use an SSO method? Which authentication method do you use?

Can you describe exactly what you do, with details on your Moodle (version and authentication) and how to replicate that.

If necessary, please fill a tracker issue, with lots of details.

Séverin