Skip to content

Commit 4354d1f

Browse files
committed
User: Invalidate user_activation_key on password update.
Props: sstoqnov, sergeybiryukov. git-svn-id: https://develop.svn.wordpress.org/trunk@47634 602fd350-edb4-49c9-b593-d223f7449a82
1 parent cfb690c commit 4354d1f

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/wp-includes/user.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ function wp_insert_user( $userdata ) {
18121812
}
18131813

18141814
if ( $update ) {
1815-
if ( $user_email !== $old_user_data->user_email ) {
1815+
if ( $user_email !== $old_user_data->user_email || $user_pass !== $old_user_data->user_pass ) {
18161816
$data['user_activation_key'] = '';
18171817
}
18181818
$wpdb->update( $wpdb->users, $data, compact( 'ID' ) );

tests/phpunit/tests/user.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ public function test_wp_update_user_should_delete_userslugs_cache() {
10361036
$this->assertEquals( $u, wp_cache_get( $updated_user->user_nicename, 'userslugs' ) );
10371037
}
10381038

1039-
function test_changing_email_invalidates_password_reset_key() {
1039+
public function test_changing_email_invalidates_password_reset_key() {
10401040
global $wpdb;
10411041

10421042
$user = $this->author;
@@ -1068,6 +1068,26 @@ function test_changing_email_invalidates_password_reset_key() {
10681068
$this->assertEmpty( $user->user_activation_key );
10691069
}
10701070

1071+
public function test_changing_password_invalidates_password_reset_key() {
1072+
global $wpdb;
1073+
1074+
$user = $this->author;
1075+
$wpdb->update( $wpdb->users, array( 'user_activation_key' => 'key' ), array( 'ID' => $user->ID ) );
1076+
clean_user_cache( $user );
1077+
1078+
$user = get_userdata( $user->ID );
1079+
$this->assertEquals( 'key', $user->user_activation_key );
1080+
1081+
$userdata = array(
1082+
'ID' => $user->ID,
1083+
'user_pass' => 'password',
1084+
);
1085+
wp_update_user( $userdata );
1086+
1087+
$user = get_userdata( $user->ID );
1088+
$this->assertEmpty( $user->user_activation_key );
1089+
}
1090+
10711091
public function test_search_users_login() {
10721092
$users = get_users(
10731093
array(

0 commit comments

Comments
 (0)