Jump to content

Update all users with password_hash


Recommended Posts

I have an old website with users and password (not hashed) and want to import them into mysql, then run a script to create a new user_password_hash and update the database:



what I tried is something like this:


require 'application/config/config.php';
#Define Connection String Using PDO.
$dbh = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8',DB_USER,DB_PASS);
$sth = $dbh->prepare("SELECT user_id, password, user_password_hash FROM users");
$result = $sth->fetchAll();
foreach($result as $key => $value)
    $query = "UPDATE users
            SET user_password_hash = password_hash('result.password', PASSWORD_DEFAULT)
            WHERE user_id = 'result.user_id'";
echo 'Done';
but not working
tried it a few different ways but unsuccessfully frustrating,
new to php, used cfm in the past, trying to get my php feet wet !!!
any suggestions are appreciated !!!
Link to comment
Share on other sites

You've used password_hash in the context of the MySQL query, but password_hash is a PHP function. You'll need to close the query string, concatenate it with your php function, then concatenate that with the remainder of your query string. Hope that makes sense.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.