diff --git a/src/wp-login.php b/src/wp-login.php
index 11517dac21..789cafcb9b 100644
--- a/src/wp-login.php
+++ b/src/wp-login.php
@@ -841,7 +841,17 @@ switch ( $action ) {
 
 		$errors = new WP_Error();
 
-		if ( isset( $_POST['pass1'] ) && $_POST['pass1'] !== $_POST['pass2'] ) {
+		// Check if password is one or all empty spaces.
+		if ( ! empty( $_POST['pass1'] ) ) {
+			$_POST['pass1'] = trim( $_POST['pass1'] );
+	
+			if ( empty( $_POST['pass1'] ) ) {
+	  			$errors->add( 'password_reset_empty_space', __( 'The password cannot be a space or all spaces.' ) );
+			}
+  		}
+
+		// Check if password fields do not match.
+		if ( ! empty( $_POST['pass1'] ) && $_POST['pass1'] !== $_POST['pass2'] ) {
 			$errors->add( 'password_reset_mismatch', __( '<strong>Error</strong>: The passwords do not match.' ) );
 		}
 
