<?php

App::import('Security', 'Utility');

class UpdatePasswordVersionShell extends AppShell {

    public $uses = array('User');

    public function main() {
        echo "Updating password hashes";
        $proceeded = $this->batchOperation(
            'User',
            '_updateHash',
            array(
                'conditions' => array('CHAR_LENGTH(password) = 32'),
                'fields' => array('id', 'password')
            )
        );
        echo "\n$proceeded password hashes updated.\n";
    }

    private function updateHashesFor($data, $model) {
        $result = array();
        foreach ($data as $row) {
            $newHash = '0 '.Security::hash($row[$model]['password'], 'blowfish');

            $result[] = array(
                'id' => $row[$model]['id'],
                'password' => $newHash,
            );
        }
        return $result;
    }

    protected function _updateHash($rows, $model) {
        $proceeded = 0;
        $data = $this->updateHashesFor($rows, $model);
        $options = array(
            'validate' => false,
            'callbacks' => false,
        );
        if ($data && $this->{$model}->saveAll($data, $options))
            $proceeded += count($data);
        return $proceeded;
    }
}

Add shell to update existing password hashes
Add shell to update existing password hashes
