diff --git a/wp-includes/user.php b/wp-includes/user.php
index ac6c0cc01b..65930c15e7 100644
--- a/wp-includes/user.php
+++ b/wp-includes/user.php
@@ -3038,15 +3038,22 @@ function retrieve_password( $user_login = null ) {
$user_login = $_POST['user_login'];
}
+ $user_login = trim( wp_unslash( $user_login ) );
+
if ( empty( $user_login ) ) {
$errors->add( 'empty_username', __( 'Error: Please enter a username or email address.' ) );
} elseif ( strpos( $user_login, '@' ) ) {
- $user_data = get_user_by( 'email', trim( wp_unslash( $user_login ) ) );
+ $user_data = get_user_by( 'email', $user_login );
+
+ if ( empty( $user_data ) ) {
+ $user_data = get_user_by( 'login', $user_login );
+ }
+
if ( empty( $user_data ) ) {
$errors->add( 'invalid_email', __( 'Error: There is no account with that username or email address.' ) );
}
} else {
- $user_data = get_user_by( 'login', trim( wp_unslash( $user_login ) ) );
+ $user_data = get_user_by( 'login', $user_login );
}
/**
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 890e995753..4191ca739f 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '6.1-beta3-54476';
+$wp_version = '6.1-beta3-54477';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.