diff --git a/auth/db/auth.php b/auth/db/auth.php index 931b4d2..86bf4b0 100644 --- a/auth/db/auth.php +++ b/auth/db/auth.php @@ -79,32 +79,38 @@ class auth_plugin_db extends auth_plugin_base { } else { // normal case: use external db for both usernames and passwords - - if ($this->config->passtype === 'md5') { // Re-format password accordingly - $extpassword = md5($extpassword); - } else if ($this->config->passtype === 'sha1') { - $extpassword = sha1($extpassword); - } - - $rs = $authdb->Execute("SELECT * FROM {$this->config->table} - WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."' - AND {$this->config->fieldpass} = '".$this->ext_addslashes($extpassword)."' "); + $rs = $authdb->Execute("SELECT {$this->config->fieldpass} FROM {$this->config->table} + WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'"); if (!$rs) { $authdb->Close(); debugging(get_string('auth_dbcantconnect','auth_db')); return false; } - if (!$rs->EOF) { - $rs->Close(); - $authdb->Close(); - return true; - } else { + if ($rs->EOF) { $rs->Close(); $authdb->Close(); return false; } + $prefix = ''; + if (strpos($rs->fields[$this->config->fieldpass], '{') === 0) { + $prefix = substr($rs->fields[$this->config->fieldpass], 0, strpos($rs->fields[$this->config->fieldpass], '}')+1); + } + + if ($this->config->passtype === 'md5') { // Re-format password accordingly + $extpassword = $prefix . md5($extpassword); + } else if ($this->config->passtype === 'sha1') { + $extpassword = $prefix . sha1($extpassword); + } else if ($this->config->passtype === 'salt') { + $extpassword = $prefix . crypt($extpassword, substr($rs->fields[$this->config->fieldpass], strlen($prefix))); + } + if (strcmp($extpassword, $rs->fields[$this->config->fieldpass]) == 0) { + return true; + } + + return false; + } } diff --git a/auth/db/config.html b/auth/db/config.html index bbdadd5..67c602c 100644 --- a/auth/db/config.html +++ b/auth/db/config.html @@ -191,6 +191,7 @@ $passtype["plaintext"] = get_string("plaintext", "auth"); $passtype["md5"] = get_string("md5", "auth"); $passtype["sha1"] = get_string("sha1", "auth"); + $passtype["salt"] = get_string("salt", "auth"); $passtype["internal"] = get_string("internal", "auth"); echo html_writer::select($passtype, "passtype", $config->passtype, false); diff --git a/lang/en/auth.php b/lang/en/auth.php index df576ec..0110960 100644 --- a/lang/en/auth.php +++ b/lang/en/auth.php @@ -113,6 +113,7 @@ $string['ntlmsso_failed'] = 'Auto-login failed, try the normal login page...'; $string['ntlmsso_isdisabled'] = 'NTLM SSO is disabled.'; $string['passwordhandling'] = 'Password field handling'; $string['plaintext'] = 'Plain text'; +$string['salt'] = 'Salted Crypt'; $string['pluginnotenabled'] = 'Authentication plugin \'{$a}\' is not enabled.'; $string['pluginnotinstalled'] = 'Authentication plugin \'{$a}\' is not installed.'; $string['potentialidps'] = 'Log in using your account on:';