1

我正在设置 Moodle 3.0 以允许来自我的 CMS(使用框架 CakePHP 2.6 开发)的用户登录到 Moodle。这两个数据库在同一台服务器上。我正在使用 Moodle 中的“外部数据库”选项,这似乎是最容易设置的解决方案。

根据 Moodle Docs,脚本/path/to/moodle/auth/db/cli/sync_users.php将用户从外部数据库 (CMS) 导入到 Moodle,这非常有效,但是使用外部数据库的凭据(用户名和密码)登录到 Moodle 不起作用。

我认为问题可能是“外部数据库”设置中的“格式密码”(我使用的是 SHA-1 哈希)。因为在 CakePHP 中有密码散列(使用盐的 SHA1)。当我将“格式密码”设置为“纯文本”时,它可以工作,但这不是我想要的。有什么办法可以解决这个问题吗?

https://docs.moodle.org/27/en/External_database_authentication

4

1 回答 1

1

我想出了一个解决我的问题的方法,但我只需要更改 Moodle 的代码的一行,这是我试图避免的。我已经尝试将“格式化密码”改为“加密单向哈希”选项,但没有成功。

我服务器上的 CakePHP 以这种方式对密码进行哈希处理:

$string = $salt_key . $password;
sha1($string);

因此,在使用“外部数据库”的 Moodle 身份验证中,我更改了文件/path/to/moodle/auth/db/auth.php并添加了以下内容:

// I've just add this line:
// $extpassword = '<your_salt_key_here>' . $extpassword;

if ($this->config->passtype === 'plaintext') {
    return ($fromdb == $extpassword);
} else if ($this->config->passtype === 'md5') {
    return (strtolower($fromdb) == md5($extpassword));
} else if ($this->config->passtype === 'sha1') {
    $extpassword = '<your_salt_key_here>' . $extpassword; // Add this line
    return (strtolower($fromdb) == sha1($extpassword));
} else if ($this->config->passtype === 'saltedcrypt') {
    require_once($CFG->libdir.'/password_compat/lib/password.php');
    return password_verify($extpassword, $fromdb);
} else {
    return false;
}
于 2015-12-23T15:39:57.260 回答