Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions features/user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ Feature: Manage WordPress users
When I run `wp user delete {USER_ID} --yes`
Then STDOUT should not be empty

When I run `wp user create testuser3 testuser3@example.com --user_pass=testuser3pass`
Then STDOUT should not contain:
"""
Password:
"""

# Check with valid password.
When I run `wp user check-password testuser3 testuser3pass`
Then the return code should be 0

# Check with invalid password.
When I try `wp user check-password testuser3 invalidpass`
Then the return code should be 1

When I try `wp user check-password invaliduser randomstring`
Then STDERR should contain:
"""
Invalid user ID, email or login: 'invaliduser'
"""
And the return code should be 1

Scenario: Reassigning user posts
Given a WP multisite install

Expand Down
37 changes: 37 additions & 0 deletions src/User_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1197,4 +1197,41 @@ private function update_msuser_status( $user_ids, $pref, $value ) {
Utils\report_batch_operation_results( 'user', $verb, count( $user_ids ), $successes, $errors );
}

/**
* Checks if a user's password is valid or not.
*
* ## OPTIONS
*
* <user>
* : The user login, user email or user ID of the user to check credentials for.
*
* <user_pass>
* : A string that contains the plain text password for the user.
*
* ## EXAMPLES
*
* # Check whether given credentials are valid; exit status 0 if valid, otherwise 1
* $ wp user check-password admin adminpass
* $ echo $?
* 1
*
* # Bash script for checking whether given credentials are valid or not
* if ! $(wp user check-password admin adminpass); then
* notify-send "Invalid Credentials";
* fi
*
* @subcommand check-password
*/
public function check_password( $args ) {

$user = $this->fetcher->get_check( $args[0] );
$user_pass = $args[1];

if ( wp_check_password( $user_pass, $user->data->user_pass, $user->ID ) ) {
WP_CLI::halt( 0 );
} else {
WP_CLI::halt( 1 );
}
}

}