poslinski.net
poslinski.net

Reputation: 201

Authentication without password on Moodle

Actually I am trying to integrate my system with moodle. I need a functionality that supposed to work like that:

  1. Login into my system (same username as in moodle db)
  2. User decide to switch to moodle, so his clicking a link to script (on moodle server - both systems are on other servers), and I getting all data from database about user that I want to log in (whole row from database) ...
  3. Because password is encrypted, I can't redirect now to login form with post params, because it won't work.

Is there any good and easy way to achieve this goal? I have username and hashed and eventually hashed password.

I am using moodle 1.9 (system requirments).

Thanks in advance for any help,

Regards David

Upvotes: 1

Views: 4122

Answers (2)

Thair
Thair

Reputation: 171

Here is what I did

1 - I enabled the (External database) Authentication Plugin

2 - Create this php file in folder (my/moodle/root/login/)

    <?php
    require('../config.php');
    $username =  $_GET['id'];// 's3265';
    $serverName = 'moodle' ;
    $connectionInfo = array( "UID"=>"mssqlUser","PWD"=>"********","Database"=>"external_Database");
//I am using MSSQL2008
        echo '<form action="' . $CFG->wwwroot . 
             '/login/index.php" method="post" name="login" id="form">';

    $conn = sqlsrv_connect( $serverName, $connectionInfo );

    if (!$conn)
       {die('Could not connect: ' . sqlsrv_error());}
    $result = sqlsrv_query($conn , "SELECT * FROM Users WHERE LoginID = '" . $username . "'");

    var_dump($conn, $result);
    while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC))
    {
            echo  $row['FName'] . " " . $row['LName'] . ", please wait. . .";
        $password =  $row['LoginPassword'];
    }
    sqlsrv_close($conn);
?>
        <p><input type="hidden" name="username" value="<?php echo $username ?>">
                <p><input type="hidden" name="password" value="<?php echo $password ?>">

        <script language="JavaScript">
             function Validate(){document.login.submit();}

             Validate();
        </script>

</form>

3 - assume you named the rhr file (test.php) now your link should look like (http://your_domain/moodle/login/test.php?id=yourusername) for me it is working , but . . . I am not concerned about security . . . if you do . . . you have to add something to this

Upvotes: 0

Jerome Mouneyrac
Jerome Mouneyrac

Reputation: 383

Some things to look at for SSO and Moodle 1.9:

Upvotes: 1

Related Questions