Files
grocy/migrations/0027.php
2026-04-20 22:46:47 +02:00

27 lines
646 B
PHP

<?php
// This is executed inside DatabaseMigrationService class/context
use Grocy\Services\DatabaseService;
$db = DatabaseService::GetInstance()->GetDbConnection();
if (defined('GROCY_HTTP_USER'))
{
// Migrate old user defined in config file to database
$newUserRow = $db->users()->createRow([
'username' => GROCY_HTTP_USER,
'password' => password_hash(GROCY_HTTP_PASSWORD, PASSWORD_ARGON2ID)
]);
$newUserRow->save();
}
else
{
// Create default user "admin" with password "admin"
$newUserRow = $db->users()->createRow([
'username' => 'admin',
'password' => password_hash('admin', PASSWORD_ARGON2ID)
]);
$newUserRow->save();
}