From 176a0b65c5dce5f996c24a3e73a76dd6467539b9 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 22 Oct 2023 22:14:25 +0200 Subject: [PATCH] Decouple setting admin password from auth provider --- .../2021_05_23_000000_set_admin_password.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/db/migrations/2021_05_23_000000_set_admin_password.php b/db/migrations/2021_05_23_000000_set_admin_password.php index a02bc5ba..8306efa5 100644 --- a/db/migrations/2021_05_23_000000_set_admin_password.php +++ b/db/migrations/2021_05_23_000000_set_admin_password.php @@ -6,14 +6,14 @@ namespace Engelsystem\Migrations; use Engelsystem\Config\Config; use Engelsystem\Database\Migration\Migration; -use Engelsystem\Helpers\Authenticator; use Illuminate\Database\Schema\Builder as SchemaBuilder; +use stdClass; class SetAdminPassword extends Migration { use Reference; - public function __construct(SchemaBuilder $schemaBuilder, protected Authenticator $auth, protected Config $config) + public function __construct(SchemaBuilder $schemaBuilder, protected Config $config) { parent::__construct($schemaBuilder); } @@ -23,12 +23,21 @@ class SetAdminPassword extends Migration */ public function up(): void { - $admin = $this->auth->authenticate('admin', 'asdfasdf'); + $db = $this->schema->getConnection(); + /** @var stdClass $admin */ + $admin = $db->table('users')->where('name', 'admin')->first(); $setupPassword = $this->config->get('setup_admin_password'); - if (!$admin || !$setupPassword) { + + if ( + !$admin + || !password_verify('asdfasdf', $admin->password) + || !$setupPassword + ) { return; } - $this->auth->setPassword($admin, $setupPassword); + $db->table('users') + ->where('id', $admin->id) + ->update(['password' => password_hash($setupPassword, PASSWORD_DEFAULT)]); } }