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;
|
||||
|
||||
use Engelsystem\Database\Migration\Migration;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CleanupShortApiKeys extends Migration
|
||||
{
|
||||
|
@ -14,8 +15,14 @@ class CleanupShortApiKeys extends Migration
|
|||
public function up(): void
|
||||
{
|
||||
$db = $this->schema->getConnection();
|
||||
foreach ($db->table('users')->get() as $user) {
|
||||
if (Str::length($user->api_key) > 42) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$db->table('users')
|
||||
->where($db->raw('LENGTH(api_key)'), '<=', 42)
|
||||
->update(['api_key' => '']);
|
||||
->where('id', $user->id)
|
||||
->update(['api_key' => bin2hex(random_bytes(32))]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue