ollybee
ollybee

Reputation: 147

Randomise all password in MySQL table

I have a MySQL database with a table that contains usernames and passwords. I want a bash script or MySQL statement that will randomise all the passwords.

I can reset one password with something like

select md5(rand()) as password;

I can loop through with a bash read while loop. Just need help putting it all together.

Yews I know there should not be passwords stored in the clear, it's a legacy system we are moving people away from.

Upvotes: 0

Views: 100

Answers (2)

Joe
Joe

Reputation: 15802

I think you should be able to just CONCAT the current password into the md5, to keep them all unique.

UPDATE passwords SET password = md5(CONCAT(RAND(), password))

Upvotes: 0

Kavi Siegel
Kavi Siegel

Reputation: 2994

UPDATE `users` SET `password` = md5(rand())

Upvotes: 2

Related Questions