最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp cli - Can I create (or update) user password with WP-CLI by hash?

programmeradmin5浏览0评论

I want to make a user-create snippet, but it must not includes plain password.

   $ wp user create username [email protected] --role=administrator --user_pass=password

So can I create (or update) user password by hashed value?

I want to make a user-create snippet, but it must not includes plain password.

   $ wp user create username [email protected] --role=administrator --user_pass=password

So can I create (or update) user password by hashed value?

Share Improve this question edited Mar 14, 2019 at 9:44 Youichi Okada asked Dec 5, 2016 at 3:36 Youichi OkadaYouichi Okada 1236 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 3

There is not "one command" in Wordpress CLI that does the job: https://github/wp-cli/wp-cli/issues/2270

However using other commands, you can overide the user password directly in the database using the following:

USER_ID=$(wp user list --login="$USR_LOGIN" --format=ids)
wp db query "UPDATE wp_users SET user_pass='$HASHED_PASS' WHERE ID = $USER_ID;"

First line is optional if you already know the user ID.

To hash a password, use the following:

wp eval "echo wp_hash_password('$CLEAR_PASSWORD');"

This should work:

wp user update USERNAME --user_pass=PASSWORD

Found it here

I know this is an old question, but I found this while looking for a similar solution. Best solution (unless you alter the DB directly) seems to be the --prompt argument. You can pass the new password over stdin with

wp user update <USER> --prompt=user_pass

This avoids having the PW show up in your history/process list.

发布评论

评论列表(0)

  1. 暂无评论