views:

45

answers:

1

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.

+3  A: 

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.

cHao
Ok how do I import it? Phpmyadmin CSV import?
lorem
And how do I import only passwords for users 5 and up? Sorry I didn't wrote it in my question, maybe I should add it there.
lorem
That could conceivably do it...though if the file already exists and looks like that, you'll need to specify that the fields are separated by spaces rather than commas. I forget whether MyAdmin will do that.
cHao
"Users 5 and up"? Clarify. The UPDATE 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, add `AND wp_users.ID >= 5` to the query.
cHao
OMG Ponies
cHao: I don't want to change passwords for users 1-4 (and I don't have them in that file). OMG Ponies: Ok, I'll try it then :). I'm using phpmyadmin - where should I (s)ftp that file to make it accessible from phpmyadmin query console?I'm wondering can WHERE be changed to something that just pulls each pass in order they're written (no username checking) and to not change anything in users 1-4?
lorem
@lorem: Has to be somewhere on the box hosting the MySQL instance, IIRC
OMG Ponies
I'm wondering can WHERE be changed to something that just pulls each pass in order they're written (no username checking) and to not change anything in users 1-4?
lorem
Ok, I'm assuming I can just add passwords 1-4 already have, then they won't change... stupid but it would work ;). What about changing passwords in order and ignoring usernames in db with new passwords?
lorem
@lorem: That, i couldn't tell you -- i don't mess with WordPress. You could only ignore "new" passwords if the DB has some concept of "new" -- ie: if it tracks when the password was changed -- which i didn't see from my quick glance at the DB schema.
cHao
@lorem: As for changing passwords "in order", that'd be a really bad idea even if it weren't a lot harder. You'll almost always want to definitively map a username (or at least an ID) to a password, so you know what password to give to what user -- and it's quite possible for IDs to be skipped (like if a user got deleted).
cHao
Yes cHao, but I just realized these passwords in file are mapped to (Display) Name field, not to id or username so I'm not sure what now -_-. Also no user was deleted. It's new install, I'm moving my site to buddypress from other platform. Users were imported manually (no import plugin could import all profile fields and avatars so it had to be manual). And now I'm trying to reset their passwords somehow. That's why I created this file with randomly generated passwords.
lorem
Ok, maybe I'll number them and use your code with id instead of username... I'll try this and if it'll work i'll choose your answer. Thanks for your time... cHao, Ponies :] (that nick just kills me)
lorem