function migrate_db()
{
    try {
        $path = makeMigrationsDir();
        $migration = new Doctrine_Migration($path);
        $migration->migrate();
        $account = db_get_account('alice');
        if (!$account) {
            $account = array('login' => 'alice', 'crypted_password' => 'b6263bb14858294c08e4bdfceba90363e10d72b4', 'name' => 'Alice Yamada', 'name_ja_kana_jp' => 'ヤマダアリサ', 'name_ja_hani_jp' => '山田亜理紗', 'given_name' => 'Alice', 'given_name_ja_kana_jp' => 'アリサ', 'given_name_ja_hani_jp' => '亜理紗', 'family_name' => 'Yamada', 'family_name_ja_kana_jp' => 'ヤマダ', 'family_name_ja_hani_jp' => '山田', 'nickname' => 'Alice Nickname', 'preferred_username' => 'AlicePreferred', 'profile' => 'http://www.wonderland.com/alice', 'picture' => 'smiling_woman.jpg', 'website' => 'http://www.wonderland.com', 'email' => '*****@*****.**', 'email_verified' => 1, 'gender' => 'Female', 'birthdate' => '2000-01-01', 'zoneinfo' => 'america/Los Angeles', 'locale' => 'en', 'phone_number' => '123-456-7890', 'phone_number_verified' => 1, 'address' => '123 Wonderland Way', 'updated_at' => time());
            db_save_account('alice', $account);
        }
        $account = db_get_account('bob');
        if (!$account) {
            $account = array('login' => 'bob', 'crypted_password' => 'cc8684eed2b6544e89242558df73a7208c9391b4', 'name' => 'Bob Ikeda', 'name_ja_kana_jp' => 'イケダボブ', 'name_ja_hani_jp' => '池田保夫', 'given_name' => 'Bob', 'given_name_ja_kana_jp' => 'ボブ', 'given_name_ja_hani_jp' => '保夫', 'family_name' => 'Ikeda', 'family_name_ja_kana_jp' => 'イケダ', 'family_name_ja_hani_jp' => '池田', 'nickname' => 'Bob Nickname', 'preferred_username' => 'BobPreferred', 'profile' => 'http://www.underland.com/bob', 'picture' => 'smiling_man.jpg', 'website' => 'http://www.underland.com', 'email' => '*****@*****.**', 'email_verified' => 1, 'gender' => 'Male', 'birthdate' => '1980-02-09', 'zoneinfo' => 'France/Paris', 'locale' => 'fr', 'phone_number' => '987-234-1234', 'phone_number_verified' => 1, 'address' => '456 Underland Ct.', 'updated_at' => time());
            db_save_account('bob', $account);
        }
    } catch (Doctrine_Migration_Exception $e) {
        if (strstr($e->getMessage(), "Already at version") === false) {
            throw $e;
        }
    } catch (Doctrine_Connection_Exception $e) {
        printf("migration exception %s\n", $e);
        die(2);
    }
}
function db_check_credential($username, $password)
{
    //    $q = Doctrine_Query::create()
    //            ->from('Account a')
    //            ->where('a.login = ? and crypted_password = ? and enabled = 1', array($username, sha1($password)));
    ////    printf("%s\n", $q->getSqlQuery());
    //    return ($q->execute()->count() == 1);
    $account = db_get_account($username);
    if ($account && $account['enabled']) {
        if (strstr($account['crypted_password'], ':') !== false) {
            return validate_password($password, $account['crypted_password']);
        } else {
            // check and migrate sha1 password to pbkdf2
            if (sha1($password) == $account['crypted_password']) {
                $values = array('crypted_password' => create_hash($password));
                db_save_account($username, $values);
                return true;
            }
        }
    }
    return false;
}