简体   繁体   English

在 Moodle 中自动验证用户身份

[英]Automatically authenticate a user in Moodle

I am trying to automatically authenticate a user in Moodle but having trouble using authenticate_user_login in Moodle 3.8.3.我正在尝试在 Moodle 中自动验证用户身份,但在 Moodle 3.8.3 中使用 authenticate_user_login 时遇到问题。 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异常 - 传递给 core\session\manager::login_user() 的参数 1 必须是 stdClass 的实例,boolean 给定,在 [dirroot]/lib/moodlelib.php 的第 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";
}



?>

I've seen this message during Moodle SSO work if the $password value passed to authenticate_user does not match the user's actual password.如果传递给authenticate_user$password值与用户的实际密码不匹配,我在 Moodle SSO 工作期间看到了此消息。 In that case, $user returns false, which is then passed to complete_user_login and eventually to login_user , triggering the error.在这种情况下, $user返回 false,然后将其传递给complete_user_login并最终传递给login_user ,从而触发错误。 After updating the password to match, all worked as expected.更新密码以匹配后,一切都按预期工作。

Guessing the same result would occur if $name does not exist or anything else that would return false from authenticate_user_login , although haven't had chance to test other scenarios.如果$name不存在或其他任何会从authenticate_user_login返回 false 的东西,猜测会出现相同的结果,尽管还没有机会测试其他场景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM