diff --git a/config/.env.example b/config/.env.example index 5bfbfe81a6..25ed90a638 100644 --- a/config/.env.example +++ b/config/.env.example @@ -34,6 +34,9 @@ export USE_CORE_ADMIN_API="false" export SHOW_TEST_METHOD="false" ## プロキシサーバーを利用するかどうか(SSL判定に利用) export TRUST_PROXY="false" +## 4系のパスワード暗号化を使用する場合は下記のコメントアウトを外し4系で利用していたセキュリティーソルトを設定する +# export HASH_TYPE="sha1" +# export SECURITY_SALT="" # Uncomment these to define cache configuration via environment variables. #export CACHE_DURATION="+2 minutes" diff --git a/plugins/baser-core/config/setting.php b/plugins/baser-core/config/setting.php index 815c30318d..857c6cd3d2 100644 --- a/plugins/baser-core/config/setting.php +++ b/plugins/baser-core/config/setting.php @@ -327,6 +327,11 @@ */ 'twoFactorAuthenticationCodeAllowTime' => 10, + /** + * 4系のパスワードでログインする際に、新しいハッシュアルゴリズムでハッシュ化するかどうか + */ + 'needsPasswordRehash' => true, + /** * エディタ */ diff --git a/plugins/baser-core/src/BaserCorePlugin.php b/plugins/baser-core/src/BaserCorePlugin.php index 60bcfcd6d0..703f272e07 100644 --- a/plugins/baser-core/src/BaserCorePlugin.php +++ b/plugins/baser-core/src/BaserCorePlugin.php @@ -43,7 +43,6 @@ use Cake\Database\Exception\MissingConnectionException; use Cake\Event\EventManager; use Cake\Http\Middleware\CsrfProtectionMiddleware; -use Cake\Http\Middleware\HttpsEnforcerMiddleware; use Cake\Http\MiddlewareQueue; use Cake\Http\ServerRequestFactory; use Cake\I18n\I18n; @@ -436,6 +435,25 @@ public function setupSessionAuth(AuthenticationService $service, array $authSett ], 'loginUrl' => Router::url($authSetting['loginAction']), ]); + + $passwordHasher = null; + if(!empty($authSetting['passwordHasher'])) { + $passwordHasher = $authSetting['passwordHasher']; + } elseif(env('HASH_TYPE') === 'sha1') { + // .env に HASH_TYPE で sha1が設定されている場合 4系のハッシュアルゴリズムを使用 + $passwordHasher = [ + 'className' => 'Authentication.Fallback', + 'hashers' => [ + 'Authentication.Default', + [ + 'className' => 'Authentication.Legacy', + 'hashType' => 'sha1', + 'salt' => true + ] + ] + ]; + } + $service->loadIdentifier('Authentication.Password', [ 'fields' => [ 'username' => $authSetting['username'], @@ -446,6 +464,7 @@ public function setupSessionAuth(AuthenticationService $service, array $authSett 'userModel' => $authSetting['userModel'], 'finder' => $authSetting['finder']?? 'available' ], + 'passwordHasher' => $passwordHasher ]); return $service; } diff --git a/plugins/baser-core/src/Controller/Admin/UsersController.php b/plugins/baser-core/src/Controller/Admin/UsersController.php index ea04c33523..7a0f0a320b 100644 --- a/plugins/baser-core/src/Controller/Admin/UsersController.php +++ b/plugins/baser-core/src/Controller/Admin/UsersController.php @@ -89,6 +89,25 @@ public function login(UsersAdminServiceInterface $service) $this->response = $service->setCookieAutoLoginKey($this->response, $user->id); } $this->BcMessage->setInfo(__d('baser_core', 'ようこそ、{0}さん。', $user->getDisplayName())); + + // baserCMS4系のパスワードでログインした場合、新しいハッシュアルゴリズムでパスワードをハッシュし直す + if (Configure::read('BcApp.needsPasswordRehash') && + $this->request->getAttribute('authentication') + ->identifiers() + ->get('Password') + ->needsPasswordRehash() + ) { + try { + $password = $this->getRequest()->getData('password'); + $service->update($user, [ + 'password_1' => $password, + 'password_2' => $password + ]); + } catch (PersistenceFailedException) { + // バリデーションでパスワードの更新に失敗した場合はスルーする + } + } + return $this->redirect($target); } else { $this->BcMessage->setError(__d('baser_core', 'Eメール、または、パスワードが間違っています。'));