Quantcast
Channel: Authentication
Viewing all articles
Browse latest Browse all 8290

Re: Login to Moodle from External Site

$
0
0
by vincent A.  

Hi Mike.,
You can create your own plugin ..I am not so thorough with the authentication concept . but this might help you.
1.create a folder name "login" in moodle/auth and save the below code as "auth.php" (check whether DB is connected  properly)
2.Then , you can see this plugin in authentication->manage Authentication.
3.Enable this plugin (plugin will not have proper name) you can  change it by using this forum (simple steps =>  http://docs.moodle.org/dev/Authentication_plugins )
4.Now you can login into moodle by your external site ..
 
I hope this will work correctly.. 

require_once($CFG->libdir.'/authlib.php');
class auth_plugin_login extends auth_plugin_base
{
      function auth_plugin_login()
     {
           $this->authtype('login');
      }
       function loginpage_hook()
       {
                  $username = isset($_GET['username']) ? $_GET['username'] : "dummy";
                  $password = isset($_GET['password']) ? $_GET['password'] : "dummy";
                  //if you need to authenticate with username and password do this....
                  // Please use the standard databse connection in moodle(this is just a sample)
                  $con = mysqli_connect("hostname","dbuser","dbpass","database");
                  $res = mysqli_query($con ,"select * from mdl_user where username = $username and password =                                                             ".md5($password));
$id = "none"     while($row = mysqli_fetch_array($res))
                        $id = $row['id'];
                 if($id == "none")
                          return ;  //If no such user is found.... Redrecting to moodle login page
                $user = get_complete_user_data('id',$id, $CFG->mnet_localhost_id);
                 complete_user_login($user);
                 redirect( $CFG->wwwroot.'/');  
                return;
            }
All the Best smile

Viewing all articles
Browse latest Browse all 8290

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>