Replace empty or too short api keys instead of resetting them
This commit is contained in:
parent
3f03d6b1d8
commit
dbbf30e233
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace Engelsystem\Migrations;
|
namespace Engelsystem\Migrations;
|
||||||
|
|
||||||
use Engelsystem\Database\Migration\Migration;
|
use Engelsystem\Database\Migration\Migration;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class CleanupShortApiKeys extends Migration
|
class CleanupShortApiKeys extends Migration
|
||||||
{
|
{
|
||||||
|
@ -14,8 +15,14 @@ class CleanupShortApiKeys extends Migration
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
$db = $this->schema->getConnection();
|
$db = $this->schema->getConnection();
|
||||||
$db->table('users')
|
foreach ($db->table('users')->get() as $user) {
|
||||||
->where($db->raw('LENGTH(api_key)'), '<=', 42)
|
if (Str::length($user->api_key) > 42) {
|
||||||
->update(['api_key' => '']);
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->table('users')
|
||||||
|
->where('id', $user->id)
|
||||||
|
->update(['api_key' => bin2hex(random_bytes(32))]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue