开发者

simple sql for mass changing passwords

Changing password for user 1 looks like this:

UPDATE `mydb`.`wp_users` 
   SET `user_pass` = MD5( 'password' ) 
 WHERE `wp_users`.`ID` = 1;

Now, I have text file with such format:

user30 pass30
...
user2 pass2
user1 pass1

How can I change passwords for all these users without doing it manually? Maybe some sql command that could import it from this file? Or some other method? I开发者_如何学编程'm using phpmyadmin, maybe I can import that data into these specific fields somehow?

I want to only import password 5 and greater.


I don't know of any SQL that will import for an update like that. However, you could import the file into a table (let's call it 'password_changes') with username and new_password fields, and then do something like

UPDATE wp_users, password_changes
SET wp_users.user_pass = md5(password_changes.new_password)
WHERE wp_users.user_login = password_changes.username

The statement above will change passwords for only those users listed in your file (and thus imported into the password_changes table). However, if you want to be extra sure users 1-4 don't get changed, add AND wp_users.ID >= 5 to the query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜