本文整理汇总了PHP中wp_set_password函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_set_password函数的具体用法?PHP wp_set_password怎么用?PHP wp_set_password使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_set_password函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: retrieve_password
/**
* Handles sending password retrieval email to user.
*
* @uses $wpdb WordPress Database object
*
* @return bool|WP_Error True: when finish. WP_Error on error
*/
function retrieve_password()
{
global $wpdb;
$errors = new WP_Error();
if (empty($_POST['user_login']) && empty($_POST['user_email'])) {
$errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.'));
}
if (strpos($_POST['user_login'], '@')) {
$user_data = get_user_by_email(trim($_POST['user_login']));
if (empty($user_data)) {
$errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
}
} else {
$login = trim($_POST['user_login']);
$user_data = get_userdatabylogin($login);
}
do_action('lostpassword_post');
if ($errors->get_error_code()) {
return $errors;
}
if (!$user_data) {
$errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.'));
return $errors;
}
// redefining user_login ensures we return the right case in the email
$user_login = $user_data->user_login;
$user_email = $user_data->user_email;
do_action('retreive_password', $user_login);
// Misspelled and deprecated
do_action('retrieve_password', $user_login);
$allow = apply_filters('allow_password_reset', true, $user_data->ID);
if (!$allow) {
return new WP_Error('no_password_reset', __('Password reset is not allowed for this user'));
} else {
if (is_wp_error($allow)) {
return $allow;
}
}
$user_email = $_POST['user_email'];
$user_login = $_POST['user_login'];
$user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE user_login = %s", $user_login));
if (empty($user)) {
return new WP_Error('invalid_key', __('Invalid key'));
}
$new_pass = wp_generate_password(12, false);
do_action('password_reset', $user, $new_pass);
wp_set_password($new_pass, $user->ID);
update_usermeta($user->ID, 'default_password_nag', true);
//Set up the Password change nag.
$message = sprintf(__('Username: %s'), $user->user_login) . "\r\n";
$message .= sprintf(__('Password: %s'), $new_pass) . "\r\n";
$message .= site_url() . '/?ptype=affiliate' . "\r\n";
$title = sprintf(__('[%s] Your new password'), get_option('blogname'));
$title = apply_filters('password_reset_title', $title);
$message = apply_filters('password_reset_message', $message, $new_pass);
if ($message && !wp_mail($user_email, $title, $message)) {
die('<p>' . __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') . '</p>');
}
return true;
}
示例2: authenticate
/**
* Authenticates the user using SAML
*
* @return void
*/
public function authenticate()
{
if (isset($_GET['loggedout']) && $_GET['loggedout'] == 'true') {
header('Location: ' . get_option('siteurl'));
exit;
} elseif ($this->settings->get_allow_sso_bypass() == true && (isset($_GET['use_sso']) && $_GET['use_sso'] == 'false' || isset($_POST['use_sso']) && $_POST['use_sso'] == 'false')) {
// User wants native WP login, do nothing
} else {
$redirect_url = array_key_exists('redirect_to', $_GET) ? wp_login_url($_GET['redirect_to']) : get_admin_url();
$this->saml->requireAuth(array('ReturnTo' => $redirect_url));
$attrs = $this->saml->getAttributes();
if (array_key_exists($this->settings->get_attribute('username'), $attrs) && array_key_exists($this->settings->get_attribute('email'), $attrs)) {
$username = $attrs[$this->settings->get_attribute('username')][0];
$email = $attrs[$this->settings->get_attribute('email')][0];
if (get_user_by('login', $username)) {
//$this->simulate_signon($username);
// FIX https://wordpress.org/support/topic/passwords-of-existing-users-not-working-how-to-update#post-6835783
require_once ABSPATH . WPINC . '/ms-functions.php';
$user = get_user_by('login', $username);
if ($user) {
$newpass = $this->user_password($username, $this->secretsauce);
wp_set_password($newpass, $user->ID);
wp_update_user(array('ID' => $user->ID, 'user_email' => $email));
}
$this->simulate_signon($username);
} else {
$this->new_user($attrs);
}
} else {
die('A username and email was not provided. ' . $this->support_message);
}
}
}
示例3: handle_on_expire_user_reset_password
/**
* Generate random password when user expires?
*/
function handle_on_expire_user_reset_password($expired_user)
{
if ($expired_user->on_expire_user_reset_password) {
$password = wp_generate_password(12, false);
wp_set_password($password, $expired_user->user_id);
}
}
示例4: reset_expired_password
function reset_expired_password($user, $new_password)
{
// Allow other actions to be fired - mirroring the standard reset password functionality
do_action('expired_password_reset', $user, $new_password);
// Reset the password for the user
wp_set_password($new_password, $user->ID);
}
示例5: retrieve_password
/**
* Handles sending password retrieval email to user.
*
* @uses $wpdb WordPress Database object
*
* @return bool|WP_Error True: when finish. WP_Error on error
*/
function retrieve_password()
{
global $wpdb;
$errors = new WP_Error();
if (empty($_POST['user_login']) && empty($_POST['user_email'])) {
$errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.', 'templatic'));
}
if (strpos($_POST['user_login'], '@')) {
$user_data = get_user_by_email(trim($_POST['user_login']));
if (empty($user_data)) {
$errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.', 'templatic'));
}
} else {
$login = trim($_POST['user_login']);
$user_data = get_userdatabylogin($login);
}
do_action('lostpassword_post');
if ($errors->get_error_code()) {
return $errors;
}
if (!$user_data) {
$errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.', 'templatic'));
return $errors;
}
// redefining user_login ensures we return the right case in the email
$user_login = $user_data->user_login;
$user_email = $user_data->user_email;
do_action('retreive_password', $user_login);
// Misspelled and deprecated
do_action('retrieve_password', $user_login);
$user_email = $_POST['user_email'];
$user_login = $_POST['user_login'];
$user = $wpdb->get_row("SELECT * FROM {$wpdb->users} WHERE user_login like \"{$user_login}\" or user_email like \"{$user_login}\"");
if (empty($user)) {
return new WP_Error('invalid_key', __('Invalid key', 'templatic'));
}
$new_pass = wp_generate_password(12, false);
do_action('password_reset', $user, $new_pass);
wp_set_password($new_pass, $user->ID);
update_usermeta($user->ID, 'default_password_nag', true);
//Set up the Password change nag.
$message = '<p><b>Your login Information :</b></p>';
$message .= '<p>' . sprintf(__('Username: %s', 'templatic'), $user->user_login) . "</p>";
$message .= '<p>' . sprintf(__('Password: %s', 'templatic'), $new_pass) . "</p>";
$message .= '<p>You can login to : <a href="' . site_url() . '/?ptype=login' . "\">Login</a> or the URL is : " . site_url() . "/?ptype=login</p>";
$message .= '<p>Thank You,<br> ' . get_option('blogname') . '</p>';
$user_email = $user_data->user_email;
$user_name = $user_data->user_nicename;
$fromEmail = get_site_emailId();
$fromEmailName = get_site_emailName();
$title = sprintf(__('[%s] Your new password', 'templatic'), get_option('blogname'));
$title = apply_filters('password_reset_title', $title);
$message = apply_filters('password_reset_message', $message, $new_pass);
if (get_option('pttthemes_send_mail') == 'Enable' || get_option('pttthemes_send_mail') == '') {
templ_sendEmail($fromEmail, $fromEmailName, $user_email, $user_name, $title, $message, $extra = '');
///forgot password email
}
return true;
}
示例6: responder_password
function responder_password()
{
$password = wp_generate_password();
wp_set_password($password, $this->user->ID);
$text = "username: " . $this->user->user_login;
$text .= "\nPassword " . $password;
return $text;
}
示例7: retrieve_password
/**
* Handles sending password retrieval email to user.
*
* @uses $wpdb WordPress Database object
*
* @return bool|WP_Error True: when finish. WP_Error on error
*/
function retrieve_password()
{
global $wpdb, $General, $Cart, $Product;
$errors = new WP_Error();
if (empty($_POST['user_login']) && empty($_POST['user_email'])) {
$errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.'));
}
if (strpos($_POST['user_login'], '@')) {
$user_data = get_user_by_email(trim($_POST['user_login']));
if (empty($user_data)) {
$errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
}
} else {
$login = trim($_POST['user_login']);
$user_data = get_userdatabylogin($login);
}
do_action('lostpassword_post');
if ($errors->get_error_code()) {
return $errors;
}
if (!$user_data) {
$errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.'));
return $errors;
}
// redefining user_login ensures we return the right case in the email
$user_login = $user_data->user_login;
$user_email = $user_data->user_email;
//do_action('retreive_password', $user_login); // Misspelled and deprecated
//do_action('retrieve_password', $user_login);
//$allow = apply_filters('allow_password_reset', true, $user_data->ID);
////////////////////////////////////
//forget pw changed on 1st april 2010 start//
$user_email = $_POST['user_email'];
$user_login = $_POST['user_login'];
$user = $wpdb->get_row("SELECT * FROM {$wpdb->users} WHERE user_login = \"{$user_login}\" or user_email = \"{$user_login}\"");
$new_pass = wp_generate_password(12, false);
wp_set_password($new_pass, $user->ID);
if ($General->is_send_forgot_pw_email()) {
$message = '<p>' . sprintf(__('Username: %s'), $user_data->user_login) . '</p>';
$message .= '<p>' . sprintf(__('Password: %s'), $new_pass) . "</p>";
$message .= '<p>You can <a href="' . $General->get_url_login(site_url('/?ptype=login')) . '">Login</a> now</p>';
$title = sprintf(__('[%s] Your new password'), get_option('blogname'));
$user_email = $user_data->user_email;
$user_login = $user_data->user_login;
$title = apply_filters('password_reset_title', $title);
$message = apply_filters('password_reset_message', $message, $new_pass);
//forget pw changed on 1st april 2010 end//
global $General;
$fromEmail = $General->get_site_emailId();
$fromEmailName = $General->get_site_emailName();
$General->sendEmail($fromEmail, $fromEmailName, $user_email, $user_login, $title, $message, $extra = '');
///To clidne email
}
return true;
}
示例8: test_password_trimming
/**
* @ticket 23494
*/
function test_password_trimming()
{
$another_user = $this->factory->user->create(array('user_login' => 'password-triming-tests'));
$passwords_to_test = array('a password with no trailing or leading spaces', 'a password with trailing spaces ', ' a password with leading spaces', ' a password with trailing and leading spaces ');
foreach ($passwords_to_test as $password_to_test) {
wp_set_password($password_to_test, $another_user);
$authed_user = wp_authenticate('password-triming-tests', $password_to_test);
$this->assertInstanceOf('WP_User', $authed_user);
$this->assertEquals($another_user, $authed_user->ID);
}
}
示例9: moove_update_password
/**
* Update user password by key
*
* @param string $key User activation key.
* @param string $password New password for user with $key.
* @return boolean
*/
public function moove_update_password($key, $password)
{
$user_id = $this->moove_get_id_by_key($key);
$user = get_user_by('id', $user_id);
if ($user !== false) {
wp_set_password($password, $user_id);
$this->moove_set_activation_key('', $user->user_login);
return true;
}
return false;
}
示例10: um_change_password_process_hook
function um_change_password_process_hook($args)
{
global $ultimatemember;
wp_set_password($args['user_password'], $args['user_id']);
delete_user_meta($args['user_id'], 'reset_pass_hash');
delete_user_meta($args['user_id'], 'reset_pass_hash_token');
do_action('um_after_changing_user_password', $args['user_id']);
if (is_user_logged_in()) {
wp_logout();
}
exit(wp_redirect(um_get_core_page('login', 'password_changed')));
}
示例11: reset_password
public static function reset_password($username)
{
if (!empty($username)) {
if (username_exists($username)) {
$user = get_user_by('login', $username);
$userdata = self::getUserDataContext($user);
$userdata['user_login'] = $username;
$userdata['password'] = wp_generate_password(12, false);
wp_set_password($userdata['password'], $user->ID);
self::sendUserEmail($userdata, 'reset-password-subject.tpl', 'reset-password-message.tpl');
}
// end if
}
}
示例12: wppb_autologin_after_password_changed
function wppb_autologin_after_password_changed()
{
if (isset($_POST['action']) && $_POST['action'] == 'edit_profile') {
if (isset($_POST['passw1']) && !empty($_POST['passw1']) && !empty($_POST['form_name'])) {
/* all the error checking filters are defined in each field file so we need them here */
if (file_exists(WPPB_PLUGIN_DIR . '/front-end/default-fields/default-fields.php')) {
require_once WPPB_PLUGIN_DIR . '/front-end/default-fields/default-fields.php';
}
if (file_exists(WPPB_PLUGIN_DIR . '/front-end/extra-fields/extra-fields.php')) {
require_once WPPB_PLUGIN_DIR . '/front-end/extra-fields/extra-fields.php';
}
/* we get the form_name through $_POST so we can apply correctly the filter so we generate the correct fields in the current form */
$form_fields = apply_filters('wppb_change_form_fields', get_option('wppb_manage_fields'), array('form_type' => 'edit_profile', 'form_fields' => array(), 'form_name' => $_POST['form_name'], 'role' => '', 'ID' => Profile_Builder_Form_Creator::wppb_get_form_id_from_form_name($_POST['form_name'], 'edit_profile')));
if (!empty($form_fields)) {
/* check for errors in the form through the filters */
$output_field_errors = array();
foreach ($form_fields as $field) {
$error_for_field = apply_filters('wppb_check_form_field_' . Wordpress_Creation_Kit_PB::wck_generate_slug($field['field']), '', $field, $_POST, 'edit_profile');
if (!empty($error_for_field)) {
$output_field_errors[$field['id']] = '<span class="wppb-form-error">' . $error_for_field . '</span>';
}
}
/* if we have no errors change the password */
if (empty($output_field_errors)) {
$user_id = get_current_user_id();
if (!is_multisite() && current_user_can('edit_users') || is_multisite() && current_user_can('manage_network')) {
if (isset($_GET['edit_user']) && !empty($_GET['edit_user'])) {
$user_id = $_GET['edit_user'];
}
}
if (!isset($_GET['edit_user'])) {
wp_clear_auth_cookie();
/* set the new password for the user */
wp_set_password($_POST['passw1'], $user_id);
// Here we calculate the expiration length of the current auth cookie and compare it to the default expiration.
// If it's greater than this, then we know the user checked 'Remember Me' when they logged in.
$logged_in_cookie = wp_parse_auth_cookie('', 'logged_in');
/** This filter is documented in wp-includes/pluggable.php */
$default_cookie_life = apply_filters('auth_cookie_expiration', 2 * DAY_IN_SECONDS, $user_id, false);
$remember = $logged_in_cookie['expiration'] - time() > $default_cookie_life;
wp_set_auth_cookie($user_id, $remember);
} else {
wp_set_password($_POST['passw1'], $user_id);
}
}
}
}
}
}
示例13: wp_check_password
/**
* Check if user has entered correct password, supports bcrypt and pHash.
*
* @param string $password Plaintext password
* @param string $hash Hash of password
* @param int|string $userId ID of user to whom password belongs
* @return mixed|void
*
* @SuppressWarnings(PHPMD.CamelCaseVariableName) $wp_hasher is a global variable, we cannot change its name
*/
function wp_check_password($password, $hash, $userId = '')
{
if (strpos($hash, WP_OLD_HASH_PREFIX) === 0) {
global $wp_hasher;
if (empty($wp_hasher)) {
require_once ABSPATH . WPINC . '/class-phpass.php';
$wp_hasher = new PasswordHash(8, true);
}
$check = $wp_hasher->CheckPassword($password, $hash);
if ($check && $userId) {
$hash = wp_set_password($password, $userId);
}
}
$check = password_verify($password, $hash);
return apply_filters('check_password', $check, $password, $hash, $userId);
}
示例14: persist
public function persist($object_id)
{
$pwd = isset($_POST[$this->get_id()]) ? $_POST[$this->get_id()] : null;
$pwd_confirm = isset($_POST[$this->get_id() . '_confirm']) ? $_POST[$this->get_id() . '_confirm'] : null;
if ($pwd == null && $pwd_confirm == NULL) {
return TRUE;
}
if ($pwd != $pwd_confirm) {
return __('The password and its confirmation do not match', 'cuar');
}
$validation_result = $this->pwd_validation_rule == null ? TRUE : $this->pwd_validation_rule->validate($this->get_arg('label'), $pwd);
if ($validation_result === TRUE) {
wp_set_password($pwd, $object_id);
}
return $validation_result;
}
示例15: test_login_acceptor_errors
/**
* Tests /login acceptor behaviour.
*
* @covers ::login
* @dataProvider data_login_errors
* @runInSeparateProcess
*
* @todo Test support for the optional 'warn' parameter.
*/
function test_login_acceptor_errors($password, $request, $messages)
{
$service = 'http://test/';
$user = get_user_by('id', $this->factory->user->create());
$username = $user->user_login;
wp_set_password($password, $user->ID);
$_POST = $request;
$_POST['username'] = $username;
try {
$this->controller->handleRequest(array('service' => $service));
} catch (WPDieException $message) {
parse_str(parse_url($this->redirect_location, PHP_URL_QUERY), $query);
}
$this->assertStringStartsWith(home_url(), $this->redirect_location, $messages['redirect']);
$this->assertFalse(isset($query['ticket']), $messages['ticket']);
// $this->markTestIncomplete( 'Test support for the optional "warn" parameter.' );
}