本文整理汇总了PHP中wp_hash_password函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_hash_password函数的具体用法?PHP wp_hash_password怎么用?PHP wp_hash_password使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_hash_password函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: scramble_password
private function scramble_password()
{
if ($this->options['scramble_passwords'] && $this->new_user == false) {
$this->user->user_pass = wp_hash_password(wp_generate_password(12, true, true));
wp_update_user($user);
}
}
示例2: value
static function value($new, $old, $post_id, $field)
{
if ($new != $old) {
return wp_hash_password(parent::value($new, $old, $post_id, $field));
} else {
return parent::value($new, $old, $post_id, $field);
}
}
示例3: wp_set_password
/**
* Set password using bcrypt
*
* @param string $password Plaintext password
* @param int $userId ID of user to whom password belongs
* @return bool|string
*/
function wp_set_password($password, $userId)
{
/** @var \wpdb $wpdb */
global $wpdb;
$hash = wp_hash_password($password);
$wpdb->update($wpdb->users, ['user_pass' => $hash, 'user_activation_key' => ''], ['ID' => $userId]);
wp_cache_delete($userId, 'users');
return $hash;
}
示例4: test_wp_hash_password_trimming
/**
* Test wp_hash_password trims whitespace
*
* This is similar to test_password_trimming but tests the "lower level"
* wp_hash_password function
*
* @ticket 24973
*/
function test_wp_hash_password_trimming()
{
$password = ' pass with leading whitespace';
$this->assertTrue(wp_check_password('pass with leading whitespace', wp_hash_password($password)));
$password = 'pass with trailing whitespace ';
$this->assertTrue(wp_check_password('pass with trailing whitespace', wp_hash_password($password)));
$password = ' pass with whitespace ';
$this->assertTrue(wp_check_password('pass with whitespace', wp_hash_password($password)));
$password = "pass with new line \n";
$this->assertTrue(wp_check_password('pass with new line', wp_hash_password($password)));
$password = "pass with vertial tab o_O\v";
$this->assertTrue(wp_check_password('pass with vertial tab o_O', wp_hash_password($password)));
}
示例5: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::$db_needed = true;
parent::set_up_before_class();
if (extension_loaded('mbstring')) {
self::$pass_1 = self::USER_PASS;
} else {
self::$pass_1 = 'Some ASCII Only PW 4 You!';
}
self::$pass_2 = '!AJd81aasjk2@';
self::$hash_1 = wp_hash_password(self::$pass_1);
self::$hash_2 = wp_hash_password(self::$pass_2);
}
示例6: signup
function signup()
{
require_once WPPR_PLUGIN_DIR . '/models/signup-model.php';
$model = new Signup_Model();
$username = sanitize_user($this->username);
$email = sanitize_email($this->email);
$password = $this->password;
$activation_key = generate_key($email);
$userdata = array($username, $email, wp_hash_password($password), $activation_key, CUR_DATE, REMOTE_IP);
if (is_wp_error($this->validate_signup())) {
$attributes['errors'] = $this->validate_signup()->get_error_message();
} else {
$result = $model->insert_signup($userdata);
if (!is_wp_error($result)) {
$attributes['success'] = 'Please check your email for confirmation';
//send email confirmation to user
$this->send_activation_link($username, $email, $password, $activation_key);
} else {
$attributes['errors'] = 'Something went wrong. Please try again later';
}
}
return $attributes;
}
示例7: bp_core_screen_signup
//.........这里部分代码省略.........
}
/**
* Fires after the validation of a new signup.
*
* @since BuddyPress (1.1.0)
*/
do_action('bp_signup_validate');
// Add any errors to the action for the field in the template for display.
if (!empty($bp->signup->errors)) {
foreach ((array) $bp->signup->errors as $fieldname => $error_message) {
// addslashes() and stripslashes() to avoid create_function()
// syntax errors when the $error_message contains quotes
/**
* Filters the error message in the loop.
*
* @since BuddyPress (1.5.0)
*
* @param string $value Error message wrapped in html.
*/
add_action('bp_' . $fieldname . '_errors', create_function('', 'echo apply_filters(\'bp_members_signup_error_message\', "<div class=\\"error\\">" . stripslashes( \'' . addslashes($error_message) . '\' ) . "</div>" );'));
}
} else {
$bp->signup->step = 'save-details';
// No errors! Let's register those deets.
$active_signup = !empty($bp->site_options['registration']) ? $bp->site_options['registration'] : '';
if ('none' != $active_signup) {
// Make sure the extended profiles module is enabled
if (bp_is_active('xprofile')) {
// Let's compact any profile field info into usermeta
$profile_field_ids = explode(',', $_POST['signup_profile_field_ids']);
// Loop through the posted fields formatting any datebox values then add to usermeta - @todo This logic should be shared with the same in xprofile_screen_edit_profile()
foreach ((array) $profile_field_ids as $field_id) {
if (!isset($_POST['field_' . $field_id])) {
if (!empty($_POST['field_' . $field_id . '_day']) && !empty($_POST['field_' . $field_id . '_month']) && !empty($_POST['field_' . $field_id . '_year'])) {
// Concatenate the values
$date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
// Turn the concatenated value into a timestamp
$_POST['field_' . $field_id] = date('Y-m-d H:i:s', strtotime($date_value));
}
}
if (!empty($_POST['field_' . $field_id])) {
$usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
}
if (!empty($_POST['field_' . $field_id . '_visibility'])) {
$usermeta['field_' . $field_id . '_visibility'] = $_POST['field_' . $field_id . '_visibility'];
}
}
// Store the profile field ID's in usermeta
$usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids'];
}
// Hash and store the password
$usermeta['password'] = wp_hash_password($_POST['signup_password']);
// If the user decided to create a blog, save those details to usermeta
if ('blog' == $active_signup || 'all' == $active_signup) {
$usermeta['public'] = isset($_POST['signup_blog_privacy']) && 'public' == $_POST['signup_blog_privacy'] ? true : false;
}
/**
* Filters the user meta used for signup.
*
* @since BuddyPress (1.1.0)
*
* @param array $usermeta Array of user meta to add to signup.
*/
$usermeta = apply_filters('bp_signup_usermeta', $usermeta);
// Finally, sign up the user and/or blog
if (isset($_POST['signup_with_blog']) && is_multisite()) {
$wp_user_id = bp_core_signup_blog($blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta);
} else {
$wp_user_id = bp_core_signup_user($_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta);
}
if (is_wp_error($wp_user_id)) {
$bp->signup->step = 'request-details';
bp_core_add_message($wp_user_id->get_error_message(), 'error');
} else {
$bp->signup->step = 'completed-confirmation';
}
}
/**
* Fires after the completion of a new signup.
*
* @since BuddyPress (1.1.0)
*/
do_action('bp_complete_signup');
}
}
/**
* Fires right before the loading of the Member registration screen template file.
*
* @since BuddyPress (1.5.0)
*/
do_action('bp_core_screen_signup');
/**
* Filters the template to load for the Member registration page screen.
*
* @since BuddyPress (1.5.0)
*
* @param string $value Path to the Member registration template to load.
*/
bp_core_load_template(apply_filters('bp_core_template_register', array('register', 'registration/register')));
}
示例8: wpmem_a_activate_user
/**
* Activates a user
*
* If registration is moderated, sets the activated flag
* in the usermeta. Flag prevents login when WPMEM_MOD_REG
* is true (1). Function is fired from bulk user edit or
* user profile update.
*
* @since 2.4
*
* @param int $user_id
* @param bool $chk_pass
* @uses $wpdb WordPress Database object
*/
function wpmem_a_activate_user($user_id, $chk_pass = false)
{
// define new_pass
$new_pass = '';
// If passwords are user defined skip this
if (!$chk_pass) {
// generates a password to send the user
$new_pass = wp_generate_password();
$new_hash = wp_hash_password($new_pass);
// update the user with the new password
global $wpdb;
$wpdb->update($wpdb->users, array('user_pass' => $new_hash), array('ID' => $user_id), array('%s'), array('%d'));
}
// if subscriptions can expire, set the user's expiration date
if (WPMEM_USE_EXP == 1) {
wpmem_set_exp($user_id);
}
// generate and send user approved email to user
require_once WPMEM_PATH . 'wp-members-email.php';
wpmem_inc_regemail($user_id, $new_pass, 2);
// set the active flag in usermeta
update_user_meta($user_id, 'active', 1);
/**
* Fires after the user activation process is complete.
*
* @since 2.8.2
*
* @param int $user_id The user's ID.
*/
do_action('wpmem_user_activated', $user_id);
return;
}
示例9: wp_update_user
/**
* Update an user in the database.
*
* It is possible to update a user's password by specifying the 'user_pass'
* value in the $userdata parameter array.
*
* If $userdata does not contain an 'ID' key, then a new user will be created
* and the new user's ID will be returned.
*
* If current user's password is being updated, then the cookies will be
* cleared.
*
* @since 2.0.0
* @see wp_insert_user() For what fields can be set in $userdata
* @uses wp_insert_user() Used to update existing user or add new one if user doesn't exist already
*
* @param array $userdata An array of user data.
* @return int The updated user's ID.
*/
function wp_update_user($userdata)
{
$ID = (int) $userdata['ID'];
// First, get all of the original fields
$user_obj = get_userdata($ID);
$user = get_object_vars($user_obj->data);
// Add additional custom fields
foreach (_get_additional_user_keys($user_obj) as $key) {
$user[$key] = get_user_meta($ID, $key, true);
}
// Escape data pulled from DB.
$user = add_magic_quotes($user);
// If password is changing, hash it now.
if (!empty($userdata['user_pass'])) {
$plaintext_pass = $userdata['user_pass'];
$userdata['user_pass'] = wp_hash_password($userdata['user_pass']);
}
wp_cache_delete($user['user_email'], 'useremail');
// Merge old and new fields with new fields overwriting old ones.
$userdata = array_merge($user, $userdata);
$user_id = wp_insert_user($userdata);
// Update the cookies if the password changed.
$current_user = wp_get_current_user();
if ($current_user->ID == $ID) {
if (isset($plaintext_pass)) {
wp_clear_auth_cookie();
wp_set_auth_cookie($ID);
}
}
return $user_id;
}
示例10: create_new_application_password
/**
* Generate a new application password.
*
* @since 0.1-dev
*
* @access public
* @static
*
* @param int $user_id User ID.
* @param string $name Password name.
* @return array The first key in the array is the new password, the second is its row in the table.
*/
public static function create_new_application_password($user_id, $name)
{
$new_password = wp_generate_password(16, false);
$hashed_password = wp_hash_password($new_password);
$new_item = array('name' => $name, 'password' => $hashed_password, 'created' => time(), 'last_used' => null, 'last_ip' => null);
$passwords = self::get_user_application_passwords($user_id);
if (!$passwords) {
$passwords = array();
}
$passwords[] = $new_item;
self::set_user_application_passwords($user_id, $passwords);
return array($new_password, $new_item);
}
示例11: wp_set_password
/**
* Updates the user's password with a new encrypted one.
*
* For integration with other applications, this function can be overwritten to
* instead use the other package password checking algorithm.
*
* @since 2.5
* @uses $wpdb WordPress database object for queries
* @uses wp_hash_password() Used to encrypt the user's password before passing to the database
*
* @param string $password The plaintext new user password
* @param int $user_id User ID
*/
function wp_set_password($password, $user_id)
{
global $wpdb;
$hash = wp_hash_password($password);
$query = $wpdb->prepare("UPDATE {$wpdb->users} SET user_pass = %s, user_activation_key = '' WHERE ID = %d", $hash, $user_id);
$wpdb->query($query);
wp_cache_delete($user_id, 'users');
}
示例12: queue_user
function queue_user($user_login, $user_pass, $user_email, $user_meta = '')
{
$sql = "INSERT INTO {$this->user_queue} (user_login, user_pass, user_email, user_timestamp, user_meta) VALUES ";
$sql .= $this->db->prepare("( %s, %s, %s, %d, %s )", $user_login, wp_hash_password($user_pass), $user_email, time(), serialize($user_meta));
$sql .= $this->db->prepare(" ON DUPLICATE KEY UPDATE user_timestamp = %d", time());
if ($this->db->query($sql)) {
return $this->db->insert_id;
} else {
return new WP_Error('queueerror', __('Could not create your user account.', 'membership'));
}
}
示例13: wppb_register_user
function wppb_register_user($global_request, $userdata)
{
$wppb_general_settings = get_option('wppb_general_settings');
$user_id = null;
$new_user_signup = false;
if (isset($wppb_general_settings['loginWith']) && $wppb_general_settings['loginWith'] == 'email') {
$userdata['user_login'] = apply_filters('wppb_generated_random_username', Wordpress_Creation_Kit_PB::wck_generate_slug(trim($userdata['user_email'])), $userdata['user_email']);
}
if (isset($wppb_general_settings['emailConfirmation']) && $wppb_general_settings['emailConfirmation'] == 'yes') {
$new_user_signup = true;
$userdata = $this->wppb_add_custom_field_values($global_request, $userdata, $this->args['form_fields']);
if (!isset($userdata['role'])) {
$userdata['role'] = $this->args['role'];
} else {
if (isset($wppb_module_settings['wppb_customRedirect']) && $wppb_module_settings['wppb_customRedirect'] == 'show' && function_exists('wppb_custom_redirect_url')) {
$this->args['redirect_url'] = wppb_custom_redirect_url('after_registration', $this->args['redirect_url'], $userdata["user_login"], $userdata['role']);
}
}
$userdata['user_pass'] = wp_hash_password($userdata['user_pass']);
if (is_multisite()) {
/* since version 2.0.7 add this meta so we know on what blog the user registered */
$userdata['registered_for_blog_id'] = get_current_blog_id();
$userdata = wp_unslash($userdata);
}
wppb_signup_user($userdata['user_login'], $userdata['user_email'], $userdata);
} else {
if (!isset($userdata['role'])) {
$userdata['role'] = $this->args['role'];
} else {
if (isset($wppb_module_settings['wppb_customRedirect']) && $wppb_module_settings['wppb_customRedirect'] == 'show' && function_exists('wppb_custom_redirect_url')) {
$this->args['redirect_url'] = wppb_custom_redirect_url('after_registration', $this->args['redirect_url'], $userdata["user_login"], $userdata['role']);
}
}
$userdata = wp_unslash($userdata);
// change User Registered date and time according to timezone selected in WordPress settings
$wppb_get_date = wppb_get_date_by_timezone();
if (isset($wppb_get_date)) {
$userdata['user_registered'] = $wppb_get_date;
}
// insert user to database
$user_id = wp_insert_user($userdata);
}
return array('userdata' => $userdata, 'user_id' => $user_id, 'new_user_signup' => $new_user_signup);
}
示例14: purchase
/**
* Generates a Purchase record from the order
*
* @since 1.1
*
* @return void
**/
function purchase () {
global $Ecart;
// Need a transaction ID to create a purchase
if (empty($this->txnid)) return false;
// Lock for concurrency protection
$this->lock();
$Purchase = new Purchase($this->txnid,'txnid');
if (!empty($Purchase->id)) {
$this->unlock();
$Ecart->resession();
$this->purchase = $Purchase->id;
if ($this->purchase !== false)
ecart_redirect(ecarturl(false,'thanks'));
}
// WordPress account integration used, customer has no wp user
if ("wordpress" == $this->accounts && empty($this->Customer->wpuser)) {
if ( $wpuser = get_current_user_id() ) $this->Customer->wpuser = $wpuser; // use logged in WordPress account
else $this->Customer->create_wpuser(); // not logged in, create new account
}
// New customer, save hashed password
if (!$this->Customer->exists() && !empty($this->Customer->password)) {
$this->Customer->id = false;
if (ECART_DEBUG) new EcartError('Creating new Ecart customer record','new_customer',ECART_DEBUG_ERR);
if ("ecart" == $this->accounts) $this->Customer->notification();
$this->Customer->password = wp_hash_password($this->Customer->password);
} else unset($this->Customer->password); // Existing customer, do not overwrite password field!
$this->Customer->save();
$this->Billing->customer = $this->Customer->id;
$this->Billing->card = substr($this->Billing->card,-4);
$paycard = Lookup::paycard($this->Billing->cardtype);
$this->Billing->cardtype = !$paycard?$this->Billing->cardtype:$paycard->name;
$this->Billing->cvv = false;
$this->Billing->save();
// Card data is truncated, switch the cart to normal mode
$Ecart->Shopping->secured(false);
if (!empty($this->Shipping->address)) {
$this->Shipping->customer = $this->Customer->id;
$this->Shipping->save();
}
$base = $Ecart->Settings->get('base_operations');
$promos = array();
foreach ($this->Cart->discounts as &$promo) {
$promos[$promo->id] = $promo->name;
$promo->uses++;
}
$Purchase = new Purchase();
$Purchase->copydata($this);
$Purchase->copydata($this->Customer);
$Purchase->copydata($this->Billing);
$Purchase->copydata($this->Shipping,'ship');
$Purchase->copydata($this->Cart->Totals);
$Purchase->customer = $this->Customer->id;
$Purchase->billing = $this->Billing->id;
$Purchase->shipping = $this->Shipping->id;
$Purchase->taxing = ($base['vat'])?'inclusive':'exclusive';
$Purchase->promos = $promos;
$Purchase->freight = $this->Cart->Totals->shipping;
$Purchase->ip = $Ecart->Shopping->ip;
$Purchase->save();
$this->unlock();
Promotion::used(array_keys($promos));
foreach($this->Cart->contents as $Item) {
$Purchased = new Purchased();
$Purchased->copydata($Item);
$Purchased->price = $Item->option->id;
$Purchased->purchase = $Purchase->id;
if (!empty($Purchased->download)) $Purchased->keygen();
$Purchased->save();
if ($Item->inventory) $Item->unstock();
}
$this->purchase = $Purchase->id;
$Ecart->Purchase = &$Purchase;
if (ECART_DEBUG) new EcartError('Purchase '.$Purchase->id.' was successfully saved to the database.',false,ECART_DEBUG_ERR);
do_action('ecart_order_notifications');
//.........这里部分代码省略.........
示例15: value
/**
* Store secured password in the database.
* @param mixed $new
* @param mixed $old
* @param int $post_id
* @param array $field
* @return string
*/
static function value($new, $old, $post_id, $field)
{
$new = $new != $old ? wp_hash_password($new) : $new;
return $new;
}