MDL-20365 auth_db: cross-db passfield case and saltedcrypt unit test

This commit is contained in:
Eloy Lafuente (stronk7) 2014-11-26 12:04:31 +01:00
parent 7bd780835b
commit e3d9fc3f5a
2 changed files with 10 additions and 2 deletions

View file

@ -105,7 +105,7 @@ class auth_plugin_db extends auth_plugin_base {
$authdb = $this->db_init(); $authdb = $this->db_init();
$rs = $authdb->Execute("SELECT {$this->config->fieldpass} $rs = $authdb->Execute("SELECT {$this->config->fieldpass} AS userpass
FROM {$this->config->table} FROM {$this->config->table}
WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'"); WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'");
if (!$rs) { if (!$rs) {
@ -119,7 +119,8 @@ class auth_plugin_db extends auth_plugin_base {
return false; return false;
} }
$fromdb = $rs->fields[$this->config->fieldpass]; $fields = array_change_key_case($rs->fields, CASE_LOWER);
$fromdb = $fields['userpass'];
$rs->Close(); $rs->Close();
$authdb->Close(); $authdb->Close();

View file

@ -306,6 +306,13 @@ class auth_db_testcase extends advanced_testcase {
$DB->update_record('auth_db_users', $user3); $DB->update_record('auth_db_users', $user3);
$this->assertTrue($auth->user_login('u3', 'heslo')); $this->assertTrue($auth->user_login('u3', 'heslo'));
require_once($CFG->libdir.'/password_compat/lib/password.php');
set_config('passtype', 'saltedcrypt', 'auth/db');
$auth->config->passtype = 'saltedcrypt';
$user3->pass = password_hash('heslo', PASSWORD_BCRYPT, array('salt' => 'best_salt_ever_moodle_rocks_dont_tell'));
$DB->update_record('auth_db_users', $user3);
$this->assertTrue($auth->user_login('u3', 'heslo'));
set_config('passtype', 'internal', 'auth/db'); set_config('passtype', 'internal', 'auth/db');
$auth->config->passtype = 'internal'; $auth->config->passtype = 'internal';
create_user_record('u3', 'heslo', 'db'); create_user_record('u3', 'heslo', 'db');