当前位置: 首页>>代码示例>>PHP>>正文


PHP validate_internal_user_password函数代码示例

本文整理汇总了PHP中validate_internal_user_password函数的典型用法代码示例。如果您正苦于以下问题:PHP validate_internal_user_password函数的具体用法?PHP validate_internal_user_password怎么用?PHP validate_internal_user_password使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了validate_internal_user_password函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 public function execute()
 {
     global $CFG, $DB;
     require_once $this->mooshDir . '/includes/passwords.php';
     require_once $CFG->libdir . '/authlib.php';
     require_once $CFG->libdir . '/moodlelib.php';
     $options = $this->expandedOptions;
     if ($options['userid']) {
         $users = $DB->get_records('user', array('id' => $options['userid']));
     } else {
         $users = $DB->get_records('user', array('deleted' => 0));
     }
     foreach ($users as $user) {
         if ($user->username == 'guest') {
             continue;
         }
         foreach ($passwords as $password) {
             if (validate_internal_user_password($user, $password)) {
                 echo "User with known (easily crackable) password: " . $user->username;
                 if ($options['reveal']) {
                     echo " / {$password}";
                 }
                 echo "\n";
                 continue 2;
             }
         }
     }
 }
开发者ID:dariogs,项目名称:moosh,代码行数:28,代码来源:AuditPasswords.php

示例2: user_login

 /**
  * Returns true if the username and password work and false if they are
  * wrong or don't exist.
  *
  * @param string $username The username
  * @param string $password The password
  * @return bool Authentication success or failure.
  */
 public function user_login($username, $password)
 {
     global $CFG, $DB;
     if ($user = $DB->get_record('user', array('username' => $username, 'mnethostid' => $CFG->mnet_localhost_id))) {
         return validate_internal_user_password($user, $password);
     }
     return false;
 }
开发者ID:posttechguy,项目名称:moodle-whia-auth_whia,代码行数:16,代码来源:auth.php

示例3: user_login

 /**
  * Returns true if the username and password work and false if they are
  * wrong or don't exist.
  *
  * @param string $username The username
  * @param string $password The password
  * @return bool Authentication success or failure.
  */
 function user_login($username, $password)
 {
     global $CFG;
     if ($user = get_record('user', 'username', $username, 'mnethostid', $CFG->mnet_localhost_id)) {
         return validate_internal_user_password($user, $password);
     }
     return false;
 }
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:16,代码来源:auth.php

示例4: user_login

 /**
  * Returns true if the username and password work and false if they are
  * wrong or don't exist.
  *
  * @param string $username The username
  * @param string $password The password
  *
  * @return bool Authentication success or failure.
  */
 function user_login($username, $password)
 {
     global $CFG, $DB;
     $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
         $rs = $authdb->Execute("SELECT * FROM {$this->config->table}\n                                     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();
             // user exists externally
             // check username/password internally
             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 {
             $rs->Close();
             $authdb->Close();
             // user does not exist externally
             return false;
         }
     } 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}\n                                WHERE {$this->config->fielduser} = '" . $this->ext_addslashes($extusername) . "'\n                                  AND {$this->config->fieldpass} = '" . $this->ext_addslashes($extpassword) . "' ");
         if (!$rs) {
             $authdb->Close();
             debugging(get_string('auth_dbcantconnect', 'auth_db'));
             return false;
         }
         if (!$rs->EOF) {
             $rs->Close();
             $authdb->Close();
             return true;
         } else {
             $rs->Close();
             $authdb->Close();
             return false;
         }
     }
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:66,代码来源:auth.php

示例5: test_version1userupdateignoresemptyvalues

 /**
  * Validates that the version 1 update ignores empty values and does not
  * blank out fields for users
  */
 public function test_version1userupdateignoresemptyvalues()
 {
     global $CFG, $DB;
     set_config('createorupdate', 0, 'dhimport_version1');
     // Create, then update a user.
     $data = array(array('entity' => 'user', 'action' => 'create', 'username' => 'rlipusername', 'password' => 'Rlippassword!0', 'firstname' => 'rlipfirstname', 'lastname' => 'rliplastname', 'email' => 'rlipuser@rlipdomain.com', 'city' => 'rlipcity', 'country' => 'CA', 'idnumber' => 'rlipidnumber'), array('entity' => 'user', 'action' => 'update', 'username' => 'rlipusername', 'password' => '', 'firstname' => 'updatedrlipfirstname', 'lastname' => '', 'email' => '', 'city' => '', 'country' => '', 'idnumber' => ''));
     $provider = new rlipimport_version1_importprovider_emptyuser($data);
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1', $provider);
     $importplugin->run();
     // Validation.
     $params = array('username' => 'rlipusername', 'mnethostid' => $CFG->mnet_localhost_id, 'firstname' => 'updatedrlipfirstname', 'lastname' => 'rliplastname', 'email' => 'rlipuser@rlipdomain.com', 'city' => 'rlipcity', 'country' => 'CA', 'idnumber' => 'rlipidnumber');
     $this->assert_record_exists('user', $params);
     // Validate password.
     $userrec = $DB->get_record('user', array('username' => $params['username']));
     $this->assertTrue(validate_internal_user_password($userrec, 'Rlippassword!0'));
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:20,代码来源:version1_empty_value_updates_test.php

示例6: user_login

 /**
  * Tells a login success when the user is logged in correctly and from one of the given IPs.
  * Cannot login when username and password are not correct, or from other IPs than those restricted ones.
  *
  * @param string $username username
  * @param string $password password
  * @return bool
  */
 function user_login($username, $password)
 {
     global $DB, $CFG;
     if ($user = $DB->get_record('user', array('username' => $username, 'mnethostid' => $CFG->mnet_localhost_id))) {
         $valid_ips = explode(',', $this->config->valid_ips);
         //check if IP is one of the restricted ones.
         $remote_addr = filter_input(INPUT_SERVER, 'REMOTE_ADDR');
         if (isset($remote_addr) && in_array($remote_addr, $valid_ips)) {
             return validate_internal_user_password($user, $password);
         } else {
             return false;
         }
     }
     // if no valid username, we do not allow to create a new user using this auth type.
     return false;
 }
开发者ID:robertboloc,项目名称:moodle-auth_ip,代码行数:24,代码来源:auth.php

示例7: user_login

 /**
  * Returns true if the username and password work and false if they are
  * wrong or don't exist. (Non-mnet accounts only!)
  *
  * @param string $username The username
  * @param string $password The password
  * @return bool Authentication success or failure.
  */
 function user_login($username, $password)
 {
     global $CFG, $DB, $USER;
     if (!($user = $DB->get_record('user', array('username' => $username, 'mnethostid' => $CFG->mnet_localhost_id)))) {
         return false;
     }
     if (!validate_internal_user_password($user, $password)) {
         return false;
     }
     if ($password === 'changeme') {
         // force the change - this is deprecated and it makes sense only for manual auth,
         // because most other plugins can not change password easily or
         // passwords are always specified by users
         set_user_preference('auth_forcepasswordchange', true, $user->id);
     }
     return true;
 }
开发者ID:abhilash1994,项目名称:moodle,代码行数:25,代码来源:auth.php

示例8: user_login

 /**
  * Authenticates user against the selected authentication provide (Ad web service)
  *
  * @param string $username The username (with system magic quotes)
  * @param string $password The password (with system magic quotes)
  * @return bool Authentication success or failure.
  */
 function user_login($username, $password)
 {
     global $DB, $CFG;
     $extusername = core_text::convert($username, 'utf-8', $this->config->extencoding);
     $extpassword = core_text::convert($password, 'utf-8', $this->config->extencoding);
     if (!$username or !$password) {
         // Don't allow blank usernames or passwords
         return false;
     }
     //retrieve the user matching username
     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;
     }
     //username must exist and have the right authentication method
     if (!empty($user) && $user->auth == 'adwebservice') {
         return true;
     }
     return false;
 }
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:28,代码来源:auth.php

示例9: testuserupdateissuccessfulwithmaxlengthfields

 /**
  * Validate that users can be updated when max-length field values are supplied
  */
 public function testuserupdateissuccessfulwithmaxlengthfields()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/data/user.class.php';
     $user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => 'test@useremail.com', 'country' => 'CA'));
     $user->save();
     $record = new stdClass();
     $record->idnumber = 'testuseridnumber';
     $record->username = 'testuserusername';
     $record->email = 'test@useremail.com';
     $record->firstname = str_repeat('a', 100);
     $record->lastname = str_repeat('a', 100);
     $record->password = 'A' . str_repeat('a', 22) . '!0';
     $record->mi = str_repeat('a', 100);
     $record->email2 = str_repeat('a', 45) . '@' . str_repeat('a', 50) . '.com';
     $record->address = str_repeat('a', 70);
     // ELIS-6795 -- mdl_user.address is only 70 characters long.
     $record->address2 = str_repeat('a', 100);
     $record->city = str_repeat('a', 100);
     $record->state = str_repeat('a', 100);
     $record->postalcode = str_repeat('a', 32);
     $record->phone = str_repeat('a', 100);
     $record->phone2 = str_repeat('a', 100);
     $record->fax = str_repeat('a', 100);
     $expectedpassword = $record->password;
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     $importplugin->user_update($record, 'bogus');
     $user = $DB->get_record(user::TABLE, array('idnumber' => $record->idnumber));
     $this->assertEquals($record->firstname, $user->firstname);
     $this->assertEquals($record->lastname, $user->lastname);
     $this->assertEquals($record->mi, $user->mi);
     $this->assertEquals($record->email2, $user->email2);
     $this->assertEquals($record->address, $user->address);
     $this->assertEquals($record->address2, $user->address2);
     $this->assertEquals($record->city, $user->city);
     $this->assertEquals($record->state, $user->state);
     $this->assertEquals($record->postalcode, $user->postalcode);
     $this->assertEquals($record->phone, $user->phone);
     $this->assertEquals($record->phone2, $user->phone2);
     $this->assertEquals($record->fax, $user->fax);
     // Validate password.
     $userrec = $DB->get_record('user', array('username' => $record->username));
     $this->assertTrue(validate_internal_user_password($userrec, $expectedpassword));
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:48,代码来源:version1elis_max_field_lengths_test.php

示例10: test_mapping_applied_during_user_update

 /**
  * Validate that mappings are applied during the user update action
  */
 public function test_mapping_applied_during_user_update()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/eliscore/lib/data/customfield.class.php';
     require_once $CFG->dirroot . '/local/elisprogram/lib/data/user.class.php';
     $this->init_mapping();
     $customfieldid = $this->create_custom_field();
     // Clear the cached custom field list.
     $usertoclearcustomfieldlist = new user();
     $usertoclearcustomfieldlist->reset_custom_field_list();
     $user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => 'testuser@email.com', 'country' => 'CA'));
     $user->save();
     // Run the user update action.
     $record = new stdClass();
     $record->customaction = 'update';
     $record->customusername = 'testuserusername';
     $record->custompassword = 'updatedTestpassword!0';
     $record->customidnumber = 'testuseridnumber';
     $record->customfirstname = 'updatedtestuserfirstname';
     $record->customlastname = 'updatedtestuserlastname';
     $record->custommi = 'updatedtestusermi';
     $record->customemail = 'testuser@email.com';
     $record->customemail2 = 'updatedtestuser@email2.com';
     $record->customaddress = 'updatedtestuseraddress';
     $record->customaddress2 = 'updatedtestuseraddress2';
     $record->customcity = 'updatedtestusercity';
     $record->customstate = 'updatedtestuserstate';
     $record->custompostalcode = 'updatedtestuserpostalcode';
     $record->customcountry = 'FR';
     $record->customphone = 'updatedtestuserphone';
     $record->customphone2 = 'updatedtestuserphone2';
     $record->customfax = 'updatedtestuserfax';
     $record->custombirthdate = 'Jan/02/2012';
     $record->customgender = 'F';
     $record->customlanguage = 'fr';
     $record->customtransfercredits = '2';
     $record->customcomments = 'updatedtestusercomments';
     $record->customnotes = 'updatedtestusernotes';
     $record->custominactive = '1';
     $record->customtestfieldshortname = '1';
     $this->run_user_import((array) $record);
     // Validation.
     $data = array('username' => 'testuserusername', 'idnumber' => 'testuseridnumber', 'firstname' => 'updatedtestuserfirstname', 'lastname' => 'updatedtestuserlastname', 'mi' => 'updatedtestusermi', 'email' => 'testuser@email.com', 'email2' => 'updatedtestuser@email2.com', 'address' => 'updatedtestuseraddress', 'address2' => 'updatedtestuseraddress2', 'city' => 'updatedtestusercity', 'state' => 'updatedtestuserstate', 'postalcode' => 'updatedtestuserpostalcode', 'country' => 'FR', 'phone' => 'updatedtestuserphone', 'phone2' => 'updatedtestuserphone2', 'fax' => 'updatedtestuserfax', 'birthdate' => '2012/01/02', 'gender' => 'F', 'language' => 'fr', 'transfercredits' => 2, 'inactive' => 1);
     $this->assertTrue($DB->record_exists(user::TABLE, $data));
     // Validate password.
     $userrec = $DB->get_record('user', array('username' => $data['username']));
     $this->assertTrue(validate_internal_user_password($userrec, 'updatedTestpassword!0'));
     $record = $DB->get_record(user::TABLE, array('username' => 'testuserusername'));
     $this->assertEquals('updatedtestusercomments', $record->comments);
     $this->assertEquals('updatedtestusernotes', $record->notes);
     $instance = \local_elisprogram\context\user::instance(1);
     $this->assertTrue($DB->record_exists(field_data_int::TABLE, array('fieldid' => $customfieldid, 'contextid' => $instance->id, 'data' => 1)));
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:56,代码来源:elis_user_field_mappings_test.php

示例11: user_login

 /**
  * Returns true if the username and password work and false if they are
  * wrong or don't exist.
  *
  * @param string $username The username (with system magic quotes)
  * @param string $password The password (with system magic quotes)
  *
  * @return bool Authentication success or failure.
  */
 function user_login($username, $password)
 {
     // therefore leave this code as is
     global $CFG;
     global $DB;
     // TODO: might set user->auth to gsaml here :/
     if ($user = $DB->get_record('user', array('username' => $username, 'mnethostid' => $CFG->mnet_localhost_id))) {
         return validate_internal_user_password($user, $password);
     }
     return false;
 }
开发者ID:stefanotirati,项目名称:moodle-google-apps,代码行数:20,代码来源:auth.php

示例12: test_update_internal_user_password

 /**
  * Test function update_internal_user_password().
  */
 public function test_update_internal_user_password()
 {
     global $DB;
     $this->resetAfterTest();
     $passwords = array('password', '1234', 'changeme', '****');
     foreach ($passwords as $password) {
         $user = $this->getDataGenerator()->create_user(array('auth' => 'manual'));
         update_internal_user_password($user, $password);
         // The user object should have been updated.
         $this->assertTrue(validate_internal_user_password($user, $password));
         // The database field for the user should also have been updated to the
         // same value.
         $this->assertSame($user->password, $DB->get_field('user', 'password', array('id' => $user->id)));
     }
     $user = $this->getDataGenerator()->create_user(array('auth' => 'manual'));
     // Manually set the user's password to the md5 of the string 'password'.
     $DB->set_field('user', 'password', '5f4dcc3b5aa765d61d8327deb882cf99', array('id' => $user->id));
     $sink = $this->redirectEvents();
     // Update the password.
     update_internal_user_password($user, 'password');
     $events = $sink->get_events();
     $sink->close();
     $event = array_pop($events);
     // Password should have been updated to a bcrypt hash.
     $this->assertFalse(password_is_legacy_hash($user->password));
     // Verify event information.
     $this->assertInstanceOf('\\core\\event\\user_password_updated', $event);
     $this->assertSame($user->id, $event->relateduserid);
     $this->assertEquals(context_user::instance($user->id), $event->get_context());
     $this->assertEventContextNotUsed($event);
     // Verify recovery of property 'auth'.
     unset($user->auth);
     update_internal_user_password($user, 'newpassword');
     $this->assertDebuggingCalled('User record in update_internal_user_password() must include field auth', DEBUG_DEVELOPER);
     $this->assertEquals('manual', $user->auth);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:39,代码来源:moodlelib_test.php

示例13: user_login

 /**
  * Returns true if the username and password work and false if they are
  * wrong or don't exist.
  *
  * @param string $username The username
  * @param string $password The password
  * @return bool Authentication success or failure.
  */
 function user_login($username, $password)
 {
     global $CFG, $DB;
     $extusername = core_text::convert($username, 'utf-8', $this->config->extencoding);
     $extpassword = core_text::convert($password, 'utf-8', $this->config->extencoding);
     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 *\n                                      FROM {$this->config->table}\n                                     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();
             // User exists externally - check username/password internally.
             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 {
             $rs->Close();
             $authdb->Close();
             // User does not exist externally.
             return false;
         }
     } 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') {
                 $extpassword = sha1($extpassword);
             }
         }
         $rs = $authdb->Execute("SELECT *\n                                      FROM {$this->config->table}\n                                     WHERE {$this->config->fielduser} = '" . $this->ext_addslashes($extusername) . "'\n                                           AND {$this->config->fieldpass} = '" . $this->ext_addslashes($extpassword) . "'");
         if (!$rs) {
             $authdb->Close();
             debugging(get_string('auth_dbcantconnect', 'auth_db'));
             return false;
         }
         if (!$rs->EOF) {
             $rs->Close();
             $authdb->Close();
             return true;
         } else {
             $rs->Close();
             $authdb->Close();
             return false;
         }
     }
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:73,代码来源:auth.php

示例14: test_version1createorupdatedeletesuser

 /**
  * Validate that when the "create or update" flag is enabled, delete
  * actions still work for a course
  */
 public function test_version1createorupdatedeletesuser()
 {
     global $CFG, $DB;
     $CFG->siteguest = 0;
     // Set up initial conditions.
     set_config('createorupdate', 1, 'dhimport_version1');
     // Validate that the standard delete action still works first create the user.
     $expecteddata = array('username' => 'rlipusername', 'mnethostid' => $CFG->mnet_localhost_id, 'firstname' => 'rlipfirstname', 'lastname' => 'rliplastname', 'email' => 'rlipuser@rlipdomain.com', 'city' => 'rlipcity', 'country' => 'CA');
     $importdata = array('entity' => 'user', 'action' => 'create', 'username' => 'rlipusername', 'password' => 'Rlippassword!1234', 'firstname' => 'rlipfirstname', 'lastname' => 'rliplastname', 'email' => 'rlipuser@rlipdomain.com', 'city' => 'rlipcity', 'country' => 'CA');
     $this->run_core_user_import($importdata);
     $this->assert_record_exists('user', $expecteddata);
     // Validate password.
     $userrec = $DB->get_record('user', array('username' => $importdata['username']));
     $this->assertTrue(validate_internal_user_password($userrec, $importdata['password']));
     // Then delete the user.
     $importdata = array('entity' => 'user', 'action' => 'delete', 'username' => 'rlipusername');
     $this->run_core_user_import($importdata);
     $all = $DB->get_records('user');
     $exists = $DB->record_exists('user', array('username' => 'rlipusername', 'deleted' => 0));
     $this->assertEquals($exists, false);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:25,代码来源:version1_createorupdate_test.php

示例15: user_login

 /**
  * Returns true if the username and password work and false if they are
  * wrong or don't exist.
  *
  * @param string $username The username
  * @param string $password The password
  * @return bool Authentication success or failure.
  */
 function user_login($username, $password)
 {
     global $CFG, $DB;
     $extusername = core_text::convert($username, 'utf-8', $this->config->extencoding);
     $extpassword = core_text::convert($password, 'utf-8', $this->config->extencoding);
     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 *\n                                      FROM {$this->config->table}\n                                     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();
             // User exists externally - check username/password internally.
             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 {
             $rs->Close();
             $authdb->Close();
             // User does not exist externally.
             return false;
         }
     } else {
         // Normal case: use external db for both usernames and passwords.
         $authdb = $this->db_init();
         $rs = $authdb->Execute("SELECT {$this->config->fieldpass} AS userpass\n                                      FROM {$this->config->table}\n                                     WHERE {$this->config->fielduser} = '" . $this->ext_addslashes($extusername) . "'");
         if (!$rs) {
             $authdb->Close();
             debugging(get_string('auth_dbcantconnect', 'auth_db'));
             return false;
         }
         if ($rs->EOF) {
             $authdb->Close();
             return false;
         }
         $fields = array_change_key_case($rs->fields, CASE_LOWER);
         $fromdb = $fields['userpass'];
         //  $rs->Close();
         //$authdb->Close();
         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') {
                     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 {
                         if ($this->config->passtype === 'tlim_alg') {
                             //$hash =new PasswordHash(8, false);
                             $rs = $authdb->Execute("SELECT * FROM {$this->config->table}\n\t\t\t\tWHERE {$this->config->fielduser} = '" . $this->ext_addslashes($extusername) . "'");
                             //$check = $hash->CheckPassword( $extpassword, $rs->fields["password"]);
                             //return $check;
                             return sha1('--' . $rs->fields["salt"] . '--' . $extpassword . '--') == $rs->fields["password"];
                         } else {
                             return false;
                         }
                     }
                 }
             }
         }
         $rs->Close();
         $authdb->Close();
     }
 }
开发者ID:blionut,项目名称:elearning,代码行数:92,代码来源:auth.php


注:本文中的validate_internal_user_password函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。