Nijn
Nijn

Reputation: 400

Update column with same data hashed

I need to update a column in the user table where there are plain text passwords stored. They need to be hashed and I don't want the users to notice this change.

$users = SELECT * FROM user

foreach ($users as $user):
UPDATE user SET password = 'new value'
endforeach;

However, how do I pass in all the plain text passwords and hash them before updating.

Upvotes: 0

Views: 816

Answers (1)

Barmar
Barmar

Reputation: 782653

The SQL UPDATE statement can read the old values of table columns and use them in the assignment.

UPDATE user
SET password = HASH_FUNCTION(password);

Replace HASH_FUNCTION with the specific function you want to use.

Upvotes: 1

Related Questions