From ba87b41b53e28ecb6225b54fca74a175e006115c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Sun, 7 Oct 2012 21:36:23 +0200 Subject: [PATCH] MDL-35695 do not connect to ext database when not necessary during login --- auth/db/auth.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/auth/db/auth.php b/auth/db/auth.php index 60babc8d877..4c95249c4a0 100644 --- a/auth/db/auth.php +++ b/auth/db/auth.php @@ -46,12 +46,22 @@ class auth_plugin_db extends auth_plugin_base { $extusername = textlib::convert($username, 'utf-8', $this->config->extencoding); $extpassword = textlib::convert($password, 'utf-8', $this->config->extencoding); - $authdb = $this->db_init(); - if ($this->is_internal()) { // lookup username externally, but resolve // password locally -- to support backend that // don't track passwords + + if (isset($this->config->removeuser) and $this->config->removeuser == AUTH_REMOVEUSER_KEEP) { + // No need to connect to external database in this case because users are never removed and we verify password locally. + if ($user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id, 'auth'=>$this->authtype))) { + return validate_internal_user_password($user, $password); + } else { + return false; + } + } + + $authdb = $this->db_init(); + $rs = $authdb->Execute("SELECT * FROM {$this->config->table} WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."' "); if (!$rs) { @@ -78,6 +88,8 @@ class auth_plugin_db extends auth_plugin_base { } else { // normal case: use external db for both usernames and passwords + $authdb = $this->db_init(); + if ($this->config->passtype === 'md5') { // Re-format password accordingly $extpassword = md5($extpassword); } else if ($this->config->passtype === 'sha1') {