3

I have a WP Network (sub directory), Sometime specially in case of security emergencies, it is generally preferred to change passwords for all users.

I am looking for a way to reset passwords by sending a password reset url via email to each user on the network.

Goal here is to just reset all passwords and make users regenerate them through the reset password link on the front end. Also I would like to kill all active sessions

The easiest way to do this is to regenerate all the SALTs (in .env for me)

How can I do this using wp-cli?

I am comparative new to wp-cli and found out https://wp-cli.org/commands/user/update/ where it explains how I can do for an individual user.

# Update user
$ wp user update 123 --display_name=Mary --user_pass=marypass
Success: Updated user 123

.

But there are two problems here,

  1. The password has to be entered along with the username, which I think is not the ideal method.
  2. The user should have the freedom to select their password,(consider strong passwords are forced)

Any help, reference Urls?

Update I was able to make a small php files which resides on my root directory, and execute in via wp-cli and reset all the passwords at once using wp_generate_password().

Since I am working on local system right now, I did not check if it sends emails with the reset URL, which is kind of important. But that does not sound too difficult.

What I am concern right now is, I really don't want it to be executed the way it is right now. I am using " wp eval-file password-reset.php;"

I want it to have it more of like a function some what like "wp reset passwords" with parameters like USERROLE, USERNAME, USERID or just * for all users.

Does anyone have any idea how can I get that???

  • I think your question might be too limiting, why do you need wp-cli for that? what is wrong with an admin based solution? – Mark Kaplun Feb 9 '17 at 6:42
  • I am considering the senerio when probably the wp-admin is not accessible or may be its hacked. This is just a emergency solution. So may not be used often, but need to have this in place when needed. – patilswapnilv Feb 9 '17 at 7:15
  • oh ok, make sense, although in case of a site being hacked it will not save you from restoring from backup first, otherwise (assuming there is a way to do it at all) the hacker most likely will be able to disable this kind of functionality – Mark Kaplun Feb 9 '17 at 9:15
  • Yes I agree with you @MarkKaplun, the hacker would be able to disable this kind of functionality. But I don't think that should stop us from having it. I have seen hackers mess with the backup files too. Long time back when tools like UpdraftPlus were commonly used and backups used to be on the same server. – patilswapnilv Feb 9 '17 at 16:08
  • This probably is more a question of Bash than WP-CLI. You could simply provide a CSV with one UID and one PW per line and then simply read that and perform the WP-CLI command for every line. – leymannx Apr 8 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.