| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace console\controllers;
- use Yii;
- use yii\helpers\Console;
- use yii\console\Controller;
- use common\models\member\Member;
- use common\helpers\StringHelper;
- /**
- * 密码初始化
- *
- * Class PasswordController
- * @package console\controllers
- */
- class PasswordController extends Controller
- {
- /**
- * 初始化
- *
- * @throws \yii\base\Exception
- */
- public function actionInit()
- {
- if ($model = Member::findOne(1)) {
- $password_hash = StringHelper::random(10);
- $model->username = StringHelper::random(5);
- $model->password_hash = Yii::$app->security->generatePasswordHash($password_hash);
- if (Member::findOne(['username' => $model->username])) {
- return $this->actionInit();
- }
- if ($model->save()) {
- Console::output('username: ' . $model->username);
- Console::output('password: ' . $password_hash);
- exit();
- }
- Console::stdout('Password initialization failed');
- exit();
- }
- Console::stdout('Cannot find administrator');
- exit();
- }
- }
|