Login and Registration: prevent registering with username that matches previous user email.

When registering a new user, check that no existing user has an email matching the username.

Prevents a login name collision when one user registers with the email address user@test.com and a second user tries to register with the username user@test.com.

Props buutqn, dunhakdis, roytanck, ajayver.
Fixes #57394.



git-svn-id: https://develop.svn.wordpress.org/trunk@55358 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Adam Silverstein
2023-02-17 08:08:19 +00:00
parent f8ec8cfe04
commit cb5eb45fab
2 changed files with 26 additions and 1 deletions

View File

@@ -934,6 +934,24 @@ class Tests_User extends WP_UnitTestCase {
$this->assertSame( $expected, $user->user_nicename );
}
/**
* @ticket 57394
*/
public function test_wp_insert_user_should_reject_username_that_matches_existing_user_email() {
$existing_email = get_option( 'admin_email' );
$username = wp_insert_user(
array(
'user_login' => $existing_email,
'user_email' => 'whatever@example.com',
'user_pass' => 'whatever',
'user_nicename' => 'whatever',
)
);
$this->assertWPError( $username );
$this->assertSame( 'existing_user_login_as_email', $username->get_error_code() );
}
/**
* @ticket 33793
*/