本文整理汇总了PHP中hash_internal_user_password函数的典型用法代码示例。如果您正苦于以下问题:PHP hash_internal_user_password函数的具体用法?PHP hash_internal_user_password怎么用?PHP hash_internal_user_password使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hash_internal_user_password函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: user_signup
/**
* Sign up a new user ready for confirmation.
* Password is passed in plaintext.
*
* @param object $user new user object (with system magic quotes)
* @param boolean $notify print notice with link and terminate
*/
function user_signup($user, $notify = true)
{
global $CFG;
require_once $CFG->dirroot . '/user/profile/lib.php';
$user->password = hash_internal_user_password($user->password);
if (!($user->id = insert_record('user', $user))) {
print_error('auth_emailnoinsert', 'auth');
}
/// Save any custom profile field information
profile_save_data($user);
$user = get_record('user', 'id', $user->id);
events_trigger('user_created', $user);
if (!send_confirmation_email($user)) {
print_error('auth_emailnoemail', 'auth');
}
if ($notify) {
global $CFG;
$emailconfirm = get_string('emailconfirm');
$navlinks = array();
$navlinks[] = array('name' => $emailconfirm, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header($emailconfirm, $emailconfirm, $navigation);
notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:34,代码来源:auth.php
示例2: user_signup
/**
* Sign up a new user ready for confirmation.
* Password is passed in plaintext.
*
* @param object $user new user object
* @param boolean $notify print notice with link and terminate
*/
function user_signup($user, $notify = true)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/user/profile/lib.php';
$user->password = hash_internal_user_password($user->password);
$user->id = $DB->insert_record('user', $user);
/// Save any custom profile field information
profile_save_data($user);
$user = $DB->get_record('user', array('id' => $user->id));
events_trigger('user_created', $user);
if (!send_confirmation_email($user)) {
print_error('auth_emailnoemail', 'auth_email');
}
if ($notify) {
global $CFG, $PAGE, $OUTPUT;
$emailconfirm = get_string('emailconfirm');
$PAGE->navbar->add($emailconfirm);
$PAGE->set_title($emailconfirm);
$PAGE->set_heading($PAGE->course->fullname);
echo $OUTPUT->header();
notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
开发者ID:JP-Git,项目名称:moodle,代码行数:32,代码来源:auth.php
示例3: test_user_update_user
/**
* Test user_update_user.
*/
public function test_user_update_user()
{
global $DB;
$this->resetAfterTest();
// Create user and modify user profile.
$user = $this->getDataGenerator()->create_user();
$user->firstname = 'Test';
$user->password = 'M00dLe@T';
// Update user and capture event.
$sink = $this->redirectEvents();
user_update_user($user);
$events = $sink->get_events();
$sink->close();
$event = array_pop($events);
// Test updated value.
$dbuser = $DB->get_record('user', array('id' => $user->id));
$this->assertSame($user->firstname, $dbuser->firstname);
$this->assertNotSame('M00dLe@T', $dbuser->password);
// Test event.
$this->assertInstanceOf('\\core\\event\\user_updated', $event);
$this->assertSame($user->id, $event->objectid);
$this->assertSame('user_updated', $event->get_legacy_eventname());
$this->assertEventLegacyData($dbuser, $event);
$this->assertEquals(context_user::instance($user->id), $event->get_context());
$expectedlogdata = array(SITEID, 'user', 'update', 'view.php?id=' . $user->id, '');
$this->assertEventLegacyLogData($expectedlogdata, $event);
// Update user with no password update.
$password = $user->password = hash_internal_user_password('M00dLe@T');
user_update_user($user, false);
$dbuser = $DB->get_record('user', array('id' => $user->id));
$this->assertSame($password, $dbuser->password);
}
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:35,代码来源:userlib_test.php
示例4: user_signup
/**
* Sign up a new user ready for confirmation.
* Password is passed in plaintext.
*
* @param object $user new user object
* @param boolean $notify print notice with link and terminate
*/
public function user_signup($user, $notify = true)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->dirroot . '/user/lib.php';
$plainpassword = $user->password;
$user->password = hash_internal_user_password($user->password);
if (empty($user->calendartype)) {
$user->calendartype = $CFG->calendartype;
}
$user->id = user_create_user($user, false, false);
user_add_password_history($user->id, $plainpassword);
// Save any custom profile field information.
profile_save_data($user);
// Trigger event.
\core\event\user_created::create_from_userid($user->id)->trigger();
if (!send_confirmation_email($user)) {
print_error('auth_emailnoemail, auth_email');
}
if ($notify) {
global $CFG, $PAGE, $OUTPUT;
$emailconfirm = get_string('emailconfirm');
$PAGE->navbar->add($emailconfirm);
$PAGE->set_title($emailconfirm);
$PAGE->set_heading($PAGE->course->fullname);
echo $OUTPUT->header();
notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
开发者ID:posttechguy,项目名称:moodle-whia-auth_whia,代码行数:38,代码来源:auth.php
示例5: user_update_user
/**
* Update a user with a user object (will compare against the ID)
* @param object $user - the user to update
*/
function user_update_user($user)
{
global $DB;
/// set the timecreate field to the current time
if (!is_object($user)) {
$user = (object) $user;
}
/// hash the password
$user->password = hash_internal_user_password($user->password);
$user->timemodified = time();
$DB->update_record('user', $user);
}
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:16,代码来源:lib.php
示例6: process_magento_request
/**
* Returns success or failure
*
* @return bool success or failure
*/
public static function process_magento_request($order_number, $customer, $moodle_courses)
{
global $USER, $DB;
if (get_config('magentoconnector', 'magentoconnectorenabled') == 0) {
return false;
}
$params = self::validate_parameters(self::process_magento_request_parameters(), array('order_number' => $order_number, 'customer' => $customer, 'moodle_courses' => $moodle_courses));
$context = context_user::instance($USER->id);
self::validate_context($context);
if (!($user = $DB->get_record('user', array('email' => $customer['email'])))) {
$user = new stdClass();
$user->firstname = $customer['firstname'];
$user->lastname = $customer['lastname'];
$user->email = $customer['email'];
$user->city = $customer['city'];
$user->country = $customer['country'];
$user->confirmed = 1;
$user->policyagreed = 1;
$user->mnethostid = 1;
$user->username = local_magentoconnector_generate_username($customer['firstname'], $customer['lastname']);
$user->timecreated = time();
$password = generate_password();
$user->password = hash_internal_user_password($password);
$userid = $DB->insert_record('user', $user);
} else {
$userid = $user->id;
}
$roleid = $DB->get_field('role', 'id', array('shortname' => LOCAL_MAGENTOCONNECTOR_STUDENT_SHORTNAME));
$enrol = enrol_get_plugin('magento');
foreach ($moodle_courses as $moodle_course) {
if ($course = $DB->get_record('course', array('idnumber' => $moodle_course['course_id']))) {
$enrolinstance = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'magento'), '*', MUST_EXIST);
$enrol->enrol_user($enrolinstance, $userid, $roleid);
$record = new stdClass();
$record->userid = $userid;
$record->ordernum = $order_number;
$record->courseid = $course->id;
$record->timestamp = time();
$DB->insert_record('local_magentoconnector_trans', $record);
} else {
// no such course ... ?
}
}
if (isset($password)) {
$enrolinstance->newusername = $user->username;
$enrolinstance->newaccountpassword = $password;
}
$customer = $DB->get_record('user', array('id' => $userid));
$enrol->email_welcome_message($enrolinstance, $customer);
return true;
}
开发者ID:srinathweb,项目名称:moodle_magento_connector,代码行数:56,代码来源:externallib.php
示例7: xmldb_local_lae_install
function xmldb_local_lae_install()
{
global $CFG, $DB;
$dbman = $DB->get_manager();
// Migrate the old config setting, if present.
if (!empty($CFG->forum_anonymous)) {
set_config('forum_enableanonymousposts', $CFG->forum_anonymous);
set_config('forum_anonymous', null);
}
// Extend forum tables.
$table = new xmldb_table('forum');
$field = new xmldb_field('anonymous');
$field->set_attributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionposts');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$table = new xmldb_table('forum_posts');
$field = new xmldb_field('hiddenuserid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, 'mailnow');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Add anonymous user.
if (empty($CFG->anonymous_userid)) {
$anon_user = new stdClass();
$anon_user->username = 'anonymous_user';
// The password needs strings.
$anon_user->password = hash_internal_user_password(str_shuffle($anon_user->username) . (string) mt_rand());
$anon_user->auth = 'nologin';
$anon_user->firstname = get_string('auser_firstname', 'local_lae');
$anon_user->lastname = get_string('auser_lastname', 'local_lae');
$anon_user->mnethostid = $CFG->mnet_localhost_id;
$anon_user->email = get_string('auser_email', 'local_lae');
if ($result = $DB->insert_record('user', $anon_user)) {
set_config('anonymous_userid', $result);
context_user::instance($result);
} else {
print_error("Failed to create anonymous user");
return false;
}
}
// Update course table to support display defaults
$table = new xmldb_table('course');
$field = new xmldb_field('filedisplaydefault', XMLDB_TYPE_INTEGER, '2', null, null, null, null, null);
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
return true;
}
开发者ID:mackensen,项目名称:moodle-local_lae,代码行数:49,代码来源:install.php
示例8: user_signup
/**
* Sign up a new user ready for confirmation.
* Password is passed in plaintext.
*
* @param object $user new user object (with system magic quotes)
* @param boolean $notify print notice with link and terminate
*/
function user_signup($user, $notify = true)
{
$user->password = hash_internal_user_password($user->password);
if (!($user->id = insert_record('user', $user))) {
print_error('auth_emailnoinsert', 'auth');
}
if (!send_confirmation_email($user)) {
print_error('auth_emailnoemail', 'auth');
}
if ($notify) {
global $CFG;
$emailconfirm = get_string('emailconfirm');
print_header($emailconfirm, $emailconfirm, $emailconfirm);
notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
开发者ID:veritech,项目名称:pare-project,代码行数:25,代码来源:auth.php
示例9: xmldb_auth_manual_upgrade
/**
* @param int $oldversion the version we are upgrading from
* @return bool result
*/
function xmldb_auth_manual_upgrade($oldversion)
{
global $CFG, $DB, $OUTPUT;
if ($oldversion < 2011022700) {
// force creation of missing passwords
$createpassword = hash_internal_user_password('');
$rs = $DB->get_recordset('user', array('password' => $createpassword, 'auth' => 'manual'));
foreach ($rs as $user) {
if (validate_email($user->email)) {
$DB->set_field('user', 'password', 'to be created', array('id' => $user->id));
unset_user_preference('auth_forcepasswordchange', $user);
set_user_preference('create_password', 1, $user);
}
}
$rs->close();
upgrade_plugin_savepoint(true, 2011022700, 'auth', 'manual');
}
return true;
}
开发者ID:esyacelga,项目名称:sisadmaca,代码行数:23,代码来源:upgrade.php
示例10: user_signup
/**
* Sign up a new user ready for confirmation.
* Password is passed in plaintext.
*
* @param object $user new user object (with system magic quotes)
* @param boolean $notify print notice with link and terminate
*/
function user_signup($user, $notify = true)
{
global $CFG;
require_once $CFG->dirroot . '/user/profile/lib.php';
$user->password = hash_internal_user_password($user->password);
if (!($user->id = insert_record('user', $user))) {
print_error('auth_emailnoinsert', 'auth');
}
/// Save any custom profile field information
profile_save_data($user);
//Added by JAM: 12.02.2010 - Call the set user time-zone for WS, cannot set time-zone until, user is created
setWSUserDefaultTimeZone($user->username, $user);
$user = get_record('user', 'id', $user->id);
events_trigger('user_created', $user);
//Added by JAM: 01.06.2011 - this is where the user id exists
if (!addQSUser($user)) {
admin_signuperror_email($user);
// Added: JAM - 01.06.2011
//error('An error has occured, please try again shortly.');
}
if (!send_confirmation_email($user)) {
print_error('auth_emailnoemail', 'auth');
}
if ($notify) {
global $CFG;
$emailconfirm = get_string('emailconfirm');
$navlinks = array();
$navlinks[] = array('name' => $emailconfirm, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header($emailconfirm, $emailconfirm, $navigation);
// Added by SMS: 7/28/2011
$data = new object();
$data->useremail = $user->email;
$supportuser = generate_email_supportuser();
$data->adminemail = $supportuser->email;
// Edited by SMS: 7/28/2011
// notice(get_string('emailconfirmsent', '', $user->email), "$CFG->wwwroot/index.php");
notice(get_string('emailconfirmsent', '', $data), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
开发者ID:arshanam,项目名称:Moodle-ITScholars-LMS,代码行数:49,代码来源:auth.php
示例11: application_user_signup
function application_user_signup($user)
{
// Derived from email->user_signup
global $CFG, $PAGE, $OUTPUT;
$user->password = hash_internal_user_password($user->password);
if (empty($user->calendartype)) {
$user->calendartype = $CFG->calendartype;
}
$user->id = user_create_user($user, false, false);
// Save any custom profile field information
profile_save_data($user);
// Save contact information
write_contact_details($user->id, $user);
// Trigger event
\core\event\user_created::create_from_userid($user->id)->trigger();
if (!send_application_confirmation_email($user)) {
print_error('auth_emailnoemail', 'auth_email');
}
$PAGE->set_title($CFG->pageheading . ': ' . get_string('emailconfirm'));
echo $OUTPUT->header();
notice(get_string('emailconfirmsent', '', $user->email), $CFG->wwwroot . '/local/obu_application/login.php');
}
开发者ID:OBU-OBIS,项目名称:moodle-local_obu_application,代码行数:22,代码来源:locallib.php
示例12: user_signup
function user_signup($user, $notify = true)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/user/profile/lib.php';
$password_clear = $user->password;
$user->password = hash_internal_user_password($user->password);
if (!($user->id = $DB->insert_record('user', $user))) {
print_error('auth_emailnoinsert', 'auth');
}
/// Save any custom profile field information
profile_save_data($user);
$conditions = array('id' => $user->id);
$user = $DB->get_record('user', $conditions);
/* Create user in Joomla */
$userinfo['username'] = $user->username;
$userinfo['password'] = $password_clear;
$userinfo['password2'] = $password_clear;
$userinfo['name'] = $user->firstname . " " . $user->lastname;
$userinfo['firstname'] = $user->firstname;
$userinfo['lastname'] = $user->lastname;
$userinfo['email'] = $user->email;
$userinfo['block'] = 1;
\core\event\user_created::create_from_userid($user->id)->trigger();
if (!send_confirmation_email($user)) {
print_error('auth_emailnoemail', 'auth');
}
if ($notify) {
$emailconfirm = get_string('emailconfirm');
$PAGE->set_url('/auth/joomdle/auth.php');
$PAGE->navbar->add($emailconfirm);
$PAGE->set_title($emailconfirm);
$PAGE->set_heading($emailconfirm);
echo $OUTPUT->header();
notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:38,代码来源:auth.php
示例13: user_signup
function user_signup($user, $notify = true)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/user/profile/lib.php';
$password_clear = $user->password;
$user->password = hash_internal_user_password($user->password);
if (!($user->id = $DB->insert_record('user', $user))) {
print_error('auth_emailnoinsert', 'auth');
}
/// Save any custom profile field information
profile_save_data($user);
$conditions = array('id' => $user->id);
$user = $DB->get_record('user', $conditions);
/* Create user in Joomla */
$userinfo['username'] = $user->username;
$userinfo['password'] = $password_clear;
$userinfo['password2'] = $password_clear;
$userinfo['name'] = $user->firstname . " " . $user->lastname;
$userinfo['email'] = $user->email;
$userinfo['block'] = 1;
$this->call_method("createUser", $userinfo);
events_trigger('user_created', $user);
if (!send_confirmation_email($user)) {
print_error('auth_emailnoemail', 'auth');
}
if ($notify) {
global $CFG;
$emailconfirm = get_string('emailconfirm');
$navlinks = array();
$navlinks[] = array('name' => $emailconfirm, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header($emailconfirm, $emailconfirm, $navigation);
notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
开发者ID:esyacelga,项目名称:sisadmaca,代码行数:37,代码来源:auth.php
示例14: test_hash_internal_user_password
/**
* Test function hash_internal_user_password().
*/
public function test_hash_internal_user_password()
{
$passwords = array('pw', 'abc123', 'C0mP1eX_&}<?@*&%` |\\"', 'ĩńťėŕňăţĩōŋāĹ');
// Check that some passwords that we convert to hashes can
// be validated.
foreach ($passwords as $password) {
$hash = hash_internal_user_password($password);
$fasthash = hash_internal_user_password($password, true);
$user = new stdClass();
$user->auth = 'manual';
$user->password = $hash;
$this->assertTrue(validate_internal_user_password($user, $password));
// They should not be in md5 format.
$this->assertFalse(password_is_legacy_hash($hash));
// Check that cost factor in hash is correctly set.
$this->assertRegExp('/\\$10\\$/', $hash);
$this->assertRegExp('/\\$04\\$/', $fasthash);
}
}
开发者ID:alanaipe2015,项目名称:moodle,代码行数:22,代码来源:moodlelib_test.php
示例15: create_user
/**
* Create a test user
* @param array|stdClass $record
* @param array $options
* @return stdClass user record
*/
public function create_user($record = null, array $options = null)
{
global $DB, $CFG;
$this->usercounter++;
$i = $this->usercounter;
$record = (array) $record;
if (!isset($record['auth'])) {
$record['auth'] = 'manual';
}
if (!isset($record['firstname']) and !isset($record['lastname'])) {
$country = rand(0, 5);
$firstname = rand(0, 4);
$lastname = rand(0, 4);
$female = rand(0, 1);
$record['firstname'] = $this->firstnames[$country * 10 + $firstname + $female * 5];
$record['lastname'] = $this->lastnames[$country * 10 + $lastname + $female * 5];
} else {
if (!isset($record['firstname'])) {
$record['firstname'] = 'Firstname' . $i;
} else {
if (!isset($record['lastname'])) {
$record['lastname'] = 'Lastname' . $i;
}
}
}
if (!isset($record['idnumber'])) {
$record['idnumber'] = '';
}
if (!isset($record['mnethostid'])) {
$record['mnethostid'] = $CFG->mnet_localhost_id;
}
if (!isset($record['username'])) {
$record['username'] = 'username' . $i;
$j = 2;
while ($DB->record_exists('user', array('username' => $record['username'], 'mnethostid' => $record['mnethostid']))) {
$record['username'] = 'username' . $i . '_' . $j;
$j++;
}
}
if (!isset($record['password'])) {
$record['password'] = 'lala';
}
if (!isset($record['email'])) {
$record['email'] = $record['username'] . '@example.com';
}
if (!isset($record['confirmed'])) {
$record['confirmed'] = 1;
}
if (!isset($record['lang'])) {
$record['lang'] = 'en';
}
if (!isset($record['maildisplay'])) {
$record['maildisplay'] = 1;
}
if (!isset($record['deleted'])) {
$record['deleted'] = 0;
}
$record['timecreated'] = time();
$record['timemodified'] = $record['timecreated'];
$record['lastip'] = '0.0.0.0';
$record['password'] = hash_internal_user_password($record['password']);
if ($record['deleted']) {
$delname = $record['email'] . '.' . time();
while ($DB->record_exists('user', array('username' => $delname))) {
$delname++;
}
$record['idnumber'] = '';
$record['email'] = md5($record['username']);
$record['username'] = $delname;
$record['picture'] = 0;
}
$userid = $DB->insert_record('user', $record);
if (!$record['deleted']) {
context_user::instance($userid);
}
return $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
}
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:83,代码来源:data_generator.php
示例16: time
$usernew->timemodified = time();
$createpassword = false;
if ($usernew->id == -1) {
unset($usernew->id);
$createpassword = !empty($usernew->createpassword);
unset($usernew->createpassword);
$usernew = file_postupdate_standard_editor($usernew, 'description', $editoroptions, null, 'user', 'profile', null);
$usernew->mnethostid = $CFG->mnet_localhost_id;
// Always local user.
$usernew->confirmed = 1;
$usernew->timecreated = time();
if ($authplugin->is_internal()) {
if ($createpassword or empty($usernew->newpassword)) {
$usernew->password = '';
} else {
$usernew->password = hash_internal_user_password($usernew->newpassword);
}
} else {
$usernew->password = AUTH_PASSWORD_NOT_CACHED;
}
$usernew->id = user_create_user($usernew, false, false);
if (!$authplugin->is_internal() and $authplugin->can_change_password() and !empty($usernew->newpassword)) {
if (!$authplugin->user_update_password($usernew, $usernew->newpassword)) {
// Do not stop here, we need to finish user creation.
debugging(get_string('cannotupdatepasswordonextauth', '', '', $usernew->auth), DEBUG_NONE);
}
}
$usercreated = true;
} else {
$usernew = file_postupdate_standard_editor($usernew, 'description', $editoroptions, $usercontext, 'user', 'profile', 0);
// Pass a true old $user here.
开发者ID:alanaipe2015,项目名称:moodle,代码行数:31,代码来源:editadvanced.php
示例17: update_internal_user_password
/**
* Update password hash in user object (if necessary).
*
* The password is updated if:
* 1. The password has changed (the hash of $user->password is different
* to the hash of $password).
* 2. The existing hash is using an out-of-date algorithm (or the legacy
* md5 algorithm).
*
* Updating the password will modify the $user object and the database
* record to use the current hashing algorithm.
* It will remove Web Services user tokens too.
*
* @param stdClass $user User object (password property may be updated).
* @param string $password Plain text password.
* @param bool $fasthash If true, use a low cost factor when generating the hash
* This is much faster to generate but makes the hash
* less secure. It is used when lots of hashes need to
* be generated quickly.
* @return bool Always returns true.
*/
function update_internal_user_password($user, $password, $fasthash = false)
{
global $CFG, $DB;
// Figure out what the hashed password should be.
if (!isset($user->auth)) {
debugging('User record in update_internal_user_password() must include field auth', DEBUG_DEVELOPER);
$user->auth = $DB->get_field('user', 'auth', array('id' => $user->id));
}
$authplugin = get_auth_plugin($user->auth);
if ($authplugin->prevent_local_passwords()) {
$hashedpassword = AUTH_PASSWORD_NOT_CACHED;
} else {
$hashedpassword = hash_internal_user_password($password, $fasthash);
}
$algorithmchanged = false;
if ($hashedpassword === AUTH_PASSWORD_NOT_CACHED) {
// Password is not cached, update it if not set to AUTH_PASSWORD_NOT_CACHED.
$passwordchanged = $user->password !== $hashedpassword;
} else {
if (isset($user->password)) {
// If verification fails then it means the password has changed.
$passwordchanged = !password_verify($password, $user->password);
$algorithmchanged = password_needs_rehash($user->password, PASSWORD_DEFAULT);
} else {
// While creating new user, password in unset in $user object, to avoid
// saving it with user_create()
$passwordchanged = true;
}
}
if ($passwordchanged || $algorithmchanged) {
$DB->set_field('user', 'password', $hashedpassword, array('id' => $user->id));
$user->password = $hashedpassword;
// Trigger event.
$user = $DB->get_record('user', array('id' => $user->id));
\core\event\user_password_updated::create_from_user($user)->trigger();
// Remove WS user tokens.
if (!empty($CFG->passwordchangetokendeletion)) {
require_once $CFG->dirroot . '/webservice/lib.php';
webservice::delete_user_ws_tokens($user->id);
}
}
return true;
}
开发者ID:lucaboesch,项目名称:moodle,代码行数:64,代码来源:moodlelib.php
示例18: while
while (!feof($fp)) {
$errors = '';
$user = new object();
// by default, use the local mnet id (this may be changed in the file)
$user->mnethostid = $CFG->mnet_localhost_id;
$line = explode($csv_delimiter, fgets($fp, LINE_MAX_SIZE));
++$linenum;
// add fields to user object
foreach ($line as $key => $value) {
if ($value !== '') {
$key = $headers[$key];
//decode encoded commas
$value = str_replace($csv_encode, $csv_delimiter, trim($value));
// special fields: password and username
if ($key == 'password' && !empty($value)) {
$user->{$key} = hash_internal_user_password($value);
} else {
if ($key == 'username') {
$value = $textlib->strtolower(addslashes($value));
if (empty($CFG->extendedusernamechars)) {
$value = eregi_replace('[^(-\\.[:alnum:])]', '', $value);
}
@$newusernames[$value]++;
$user->{$key} = $value;
} else {
$user->{$key} = addslashes($value);
}
}
}
}
// add default values for remaining fields
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:31,代码来源:uploaduser.php
示例19: update_internal_user_password
/**
* Update pssword hash in user object.
*
* @param object user
* @param string plain text password
* @param bool store changes also in db, default true
* @return true if hash changed
*/
function update_internal_user_password(&$user, $password)
{
global $CFG;
$authplugin = get_auth_plugin($user->auth);
if ($authplugin->prevent_local_passwords()) {
$hashedpassword = 'not cached';
} else {
$hashedpassword = hash_internal_user_password($password);
}
return set_field('user', 'password', $hashedpassword, 'id', $user->id);
}
开发者ID:nadavkav,项目名称:rtlMoodle,代码行数:19,代码来源:moodlelib.php
示例20: setnew_password_and_mail
/**
* Sets specified user's password and send the new password to the user via email.
*
* @global object
* @global object
* @param user $user A {@link $USER} object
* @return boolean|string Returns "true" if mail was sent OK and "false" if there was an error
*/
function setnew_password_and_mail($user)
{
global $CFG, $DB;
$site = get_site();
$supportuser = generate_email_supportuser();
$newpassword = generate_password();
$DB->set_field('user', 'password', hash_internal_user_password($newpassword), array('id' => $user->id));
$a = new stdClass();
$a->firstname = fullname($user, true);
$a->sitename = format_string($site->fullname);
$a->username = $user->username;
$a->newpassword = $newpassword;
$a->link = $CFG->wwwroot . '/login/';
$a->signoff = generate_email_signoff();
$message = get_string('newusernewpasswordtext', '', $a);
$subject = format_string($site->fullname) . ': ' . get_string('newusernewpasswordsubj');
//directly email rather than using the messaging system to ensure its not routed to a popup or jabber
return email_to_user($user, $supportuser, $subject, $message);
}
开发者ID:hitphp,项目名称:moodle,代码行数:27,代码来源:moodlelib.php
注:本文中的hash_internal_user_password函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论