From 1c7ca2a99943dc9ad5881db4ec59006d9e89ade6 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 31 Jul 2025 10:02:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command/InitUserPasswordCommand.php | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 app/command/InitUserPasswordCommand.php diff --git a/app/command/InitUserPasswordCommand.php b/app/command/InitUserPasswordCommand.php new file mode 100644 index 0000000..bdf76b5 --- /dev/null +++ b/app/command/InitUserPasswordCommand.php @@ -0,0 +1,34 @@ +orWhere('password', '')->get(); + $count = 0; + + foreach ($users as $user) { + if (!empty($user->sn)) { + $user->password = password_hash($user->sn, PASSWORD_DEFAULT); + $user->save(); + $output->writeln("用户ID {$user->id} 密码已初始化"); + $count++; + } else { + $output->writeln("用户ID {$user->id} 的sn字段为空,无法初始化密码"); + } + } + + $output->writeln("共初始化 {$count} 个用户密码"); + return self::SUCCESS; + } +} \ No newline at end of file