There may be times where you find yourself locked out of WordPress admin, for example whilst migrating sites between environments or when spinning up a new site instance. In these instances, updating a user's password directly through the database isn't possible due to hashing.
Fortunately, there is a simple way to update a WordPress user's password through the WP-CLI by using the command below. Where USERNAME is used below, you can pass the username, user ID or the user's email address.
SHELL
wp user update USERNAME --user_pass="PASSWORD"WP-CLI is a set of command line tools for WordPress, allowing you to run common admin tasks directly from your terminal. If you need to install WP-CLI before running the command above, you can follow the instructions found on https://wordpress.org/cli/.