Fix password reset

Fixes #6049
This commit is contained in:
Mike Jolley 2014-08-19 10:43:48 +01:00
parent 73dfba8573
commit c6fe731337
2 changed files with 17 additions and 13 deletions

View File

@ -212,12 +212,14 @@ class WC_Shortcode_My_Account {
/**
* Handles sending password retrieval email to customer.
*
* Based on retrieve_password() in core wp-login.php
*
* @access public
* @uses $wpdb WordPress Database object
* @return bool True: when finish. False: on error
*/
public static function retrieve_password() {
global $woocommerce,$wpdb;
global $wpdb, $wp_hasher;
if ( empty( $_POST['user_login'] ) ) {
@ -234,7 +236,7 @@ class WC_Shortcode_My_Account {
$user_data = get_user_by( 'email', trim( $_POST['user_login'] ) );
}
do_action('lostpassword_post');
do_action( 'lostpassword_post' );
if ( ! $user_data ) {
wc_add_notice( __( 'Invalid username or e-mail.', 'woocommerce' ), 'error' );
@ -247,7 +249,7 @@ class WC_Shortcode_My_Account {
do_action( 'retrieve_password', $user_login );
$allow = apply_filters('allow_password_reset', true, $user_data->ID);
$allow = apply_filters( 'allow_password_reset', true, $user_data->ID );
if ( ! $allow ) {
@ -262,19 +264,20 @@ class WC_Shortcode_My_Account {
return false;
}
$key = $wpdb->get_var( $wpdb->prepare( "SELECT user_activation_key FROM $wpdb->users WHERE user_login = %s", $user_login ) );
$key = wp_generate_password( 20, false );
if ( empty( $key ) ) {
do_action( 'retrieve_password_key', $user_login, $key );
// Generate something random for a key...
$key = wp_generate_password( 20, false );
do_action('retrieve_password_key', $user_login, $key);
// Now insert the new md5 key into the db
$wpdb->update( $wpdb->users, array( 'user_activation_key' => $key ), array( 'user_login' => $user_login ) );
// Now insert the key, hashed, into the DB.
if ( empty( $wp_hasher ) ) {
require_once ABSPATH . 'wp-includes/class-phpass.php';
$wp_hasher = new PasswordHash( 8, true );
}
$hashed = $wp_hasher->HashPassword( $key );
$wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user_login ) );
// Send email notification
$mailer = WC()->mailer();
do_action( 'woocommerce_reset_password_notification', $user_login, $key );
@ -294,7 +297,7 @@ class WC_Shortcode_My_Account {
* @return object|bool User's database row on success, false for invalid keys
*/
public static function check_password_reset_key( $key, $login ) {
global $woocommerce,$wpdb;
global $wpdb;
$key = preg_replace( '/[^a-z0-9]/i', '', $key );

View File

@ -141,6 +141,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Feature - Ability to set a maximum spend for coupons.
* Feature - Added Simplify Commerce payment gateway.
* Fix - Allow endpoint use on the front page.
* Fix - user_activation_key password reset code.
* Tweak - Recalculate the cart totals, in the event a user registers during checkout and in doing so qualifies for any discounts.
* Tweak - Use `woocommerce_valid_order_statuses_for_payment` in `pay_action` too.
* Tweak - Added the possibility to translate the edit-address endpoint slug.