Skip to content

Commit 5c4e18c

Browse files
Add option for wp_slash() on check-password and a warning
1 parent 04e9a16 commit 5c4e18c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/User_Command.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,9 @@ private function update_msuser_status( $user_ids, $pref, $value ) {
12681268
* <user_pass>
12691269
* : A string that contains the plain text password for the user.
12701270
*
1271+
* [--escape-chars]
1272+
* : Escape password with `wp_slash()` to mimic the same behavior as `wp-login.php`.
1273+
*
12711274
* ## EXAMPLES
12721275
*
12731276
* # Check whether given credentials are valid; exit status 0 if valid, otherwise 1
@@ -1282,10 +1285,16 @@ private function update_msuser_status( $user_ids, $pref, $value ) {
12821285
*
12831286
* @subcommand check-password
12841287
*/
1285-
public function check_password( $args ) {
1288+
public function check_password( $args, $assoc_args ) {
1289+
1290+
$escape_chars = Utils\get_flag_value( $assoc_args, 'escape-chars', false );
1291+
1292+
if ( ! $escape_chars && wp_slash( wp_unslash( $args[1] ) ) !== $args[1] ) {
1293+
WP_CLI::warning( 'Password contains characters that need to be escaped. Please escape them manually or use the `--escape-chars` option.' );
1294+
}
12861295

12871296
$user = $this->fetcher->get_check( $args[0] );
1288-
$user_pass = $args[1];
1297+
$user_pass = $escape_chars ? wp_slash( $args[1] ) : $args[1];
12891298

12901299
if ( wp_check_password( $user_pass, $user->data->user_pass, $user->ID ) ) {
12911300
WP_CLI::halt( 0 );

0 commit comments

Comments
 (0)