winter/modules/backend/database/seeds/DatabaseSeeder.php
Saifur Rahman Mohsin 59de6e1d25
Respect user-defined admin password during october:install(#5481)
During the regular october install using october:install, the user-defined password is overwritten with the random generated string password. Instead, now it uses random password only if the user-defined password defaults to *admin* and if a user did set a custom password, that is used instead.
2021-02-26 13:49:52 -06:00

33 lines
996 B
PHP

<?php namespace Backend\Database\Seeds;
use Str;
use Seeder;
use Eloquent;
use Backend\Database\Seeds\SeedSetupAdmin;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return string
*/
public function run()
{
$shouldRandomizePassword = SeedSetupAdmin::$password === 'admin';
$adminPassword = $shouldRandomizePassword ? Str::random(22) : SeedSetupAdmin::$password;
Eloquent::unguarded(function () use ($adminPassword) {
// Generate a random password for the seeded admin account
$adminSeeder = new \Backend\Database\Seeds\SeedSetupAdmin;
$adminSeeder->setDefaults([
'password' => $adminPassword
]);
$this->call($adminSeeder);
});
return $shouldRandomizePassword ? 'The following password has been automatically generated for the "admin" account: '
. "<fg=yellow;options=bold>${adminPassword}</>" : '';
}
}