Automatically authenticate a user in Moodle

Automatically authenticate a user in Moodle

por Luke P -
Número de respostas: 4

I am trying to automatically authenticate a user but having trouble using authenticate_user_login in Moodle 3.8.3. I have tested the below code but I get the following error:

Exception - Argument 1 passed to core\session\manager::login_user() must be an instance of stdClass, boolean given, called in [dirroot]/lib/moodlelib.php on line 4632

Appreciate your help.

<?php
require('config.php');
$name="myusername";
$password="mypassword";
$dashboard = $CFG->wwwroot;
$user = authenticate_user_login($name, $password);
if(complete_user_login($user))
{
echo "login";
}
else
{
   echo "not login";
}
?>


Média das avaliações:  -
Em resposta à Luke P

Re: Automatically authenticate a user in Moodle

por Luke P -
Any ideas?
Em resposta à Luke P

Re: Automatically authenticate a user in Moodle

por John Doyle -

Hi - I've seen this message during SSO work if the $password value passed to authenticate_user does not match the user's actual password. In that case, $user returned false, which was then passed to complete_user_login and eventually to login_user() , triggering the error.  The same thing may occur if authenticate_user_login returns false for anything - e.g. if $name does not exist, but have not encountered/tested that scenario. 

Em resposta à Luke P

Re: Automatically authenticate a user in Moodle

por Daniel Rodriguez -
Hello, I am in a similar situation. I want to auto login the user. Have you found a solution?

Greetings.