diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php
index 4c4b3f2040ffd84a6da6da45205d64242a78917f..83abf3ba9de61700f3f8990d915068fd26a381e3 100644
--- a/apps/files_encryption/hooks/hooks.php
+++ b/apps/files_encryption/hooks/hooks.php
@@ -80,8 +80,15 @@ class Hooks {
 
 		// Check if first-run file migration has already been performed
 		$ready = false;
-		if ($util->getMigrationStatus() === Util::MIGRATION_OPEN) {
+		$migrationStatus = $util->getMigrationStatus();
+		if ($migrationStatus === Util::MIGRATION_OPEN) {
 			$ready = $util->beginMigration();
+		} elseif ($migrationStatus === Util::MIGRATION_IN_PROGRESS) {
+			// refuse login as long as the initial encryption is running
+			while ($migrationStatus === Util::MIGRATION_IN_PROGRESS) {
+				sleep(60);
+				$migrationStatus = $util->getMigrationStatus();
+			}
 		}
 
 		// If migration not yet done