diff --git a/.gitmodules b/.gitmodules
index a2e8d186207ec070b5ce6dd5a73039fba40cadde..fbf336cc01c1c94c5e60b30615e232cda865ab28 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,3 @@
-[submodule "vendor/libpatrix"]
+[submodule "libpatrix"]
 	path = vendor/libpatrix
 	url = git@gitlab.data-quest.de:strohm/libpatrix.git
diff --git a/controllers/matrix_chat.php b/controllers/matrix_chat.php
index dbbb664f3079427f40dce953ab2d59f772a3c1fd..9b56f1219e8e108137755d41bc5ed6626a2826df 100644
--- a/controllers/matrix_chat.php
+++ b/controllers/matrix_chat.php
@@ -40,24 +40,39 @@ class MatrixChatController extends AuthenticatedController
     {
         Navigation::activateItem('/course/matrix/matrix_chat');
 
+        if (!Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) {
+            PageLayout::postInfo(
+                sprintf(
+                    dgettext('matrix', 'Sollten Sie sich noch nie beim Chat angemeldet haben, ' .
+                        'tun Sie dies bitte jetzt und %sladen danach die Seite neu%s.'),
+                    '<a href="" title="' . dgettext('matrix', 'Seite neu laden') . '">',
+                    '</a>'
+                )
+            );
+        }
+
         // Check if current user has a Matrix account.
         $this->account = MatrixAccount::find(User::findCurrent()->id);
 
-        // If no account is found, try to search in Matrix user directory.
-        $found = MatrixClient::get()->searchUsers(
-            MatrixAccount::requireSystemAccount(), '@studip_test1:', 1);
-
-        PageLayout::postInfo('<pre>' . print_r($found, 1) . '</pre>');
-
         $this->no_account_wanted = UserConfig::get(User::findCurrent()->id)->MATRIX_NO_ACCOUNT_WANTED;
 
-        if ($this->account) {
+        if (!$this->account && !Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) {
+            $this->account = new MatrixAccount();
+            $this->account->user_id = User::findCurrent()->id;
+            $this->account->matrix_account_id = '@' . User::findCurrent()->username . ':' . Config::get()->MATRIX_SERVER_HOSTNAME;
+            $this->account->matrix_password = '';
+            $this->account->store();
+        }
+
+        $this->hasToCreate = false;
+        if ($this->account || !Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) {
             if (!($room = MatrixRoom::findOneByRange_id(Course::findCurrent()->id))) {
                 $this->hasToCreate = true;
             } else {
                 $this->hasToCreate = false;
 
-                $room->requireMembership($this->account->getLinkedAccount());
+                //$room->requireMembership($this->account->getLinkedAccount());
+                $room->requireInvitation($this->account->getLinkedAccount());
             }
         }
 
diff --git a/migrations/20210519_init_matrix_chat.php b/migrations/20210519_init_matrix_chat.php
index 47381a3cf1e4ab252df955c6628a1b9d95e56d8a..bd34aa421b158d104bf804a7c4935d2fb4aae3d8 100644
--- a/migrations/20210519_init_matrix_chat.php
+++ b/migrations/20210519_init_matrix_chat.php
@@ -77,9 +77,9 @@ class InitMatrixChat extends Migration
                 'section' => 'matrix',
                 'description' => 'URL des Chatservers (z.B. Element)'
             ],
-            'AUTO_CREATE_ACCOUNTS' => [
+            'MATRIX_AUTO_CREATE_ACCOUNTS' => [
                 'value' => false,
-                'type' => 'bool',
+                'type' => 'boolean',
                 'range' => 'global',
                 'section' => 'matrix',
                 'description' => 'Soll automatisch versucht werden, Matrixaccounts anzulegen? Andernfalls wird ' .
diff --git a/models/MatrixAccount.php b/models/MatrixAccount.php
index 091e4b0bee828b4c23831e421e5c38a5df0c974a..2ba32ddecca40c934752bb50cb40ed816627d615 100644
--- a/models/MatrixAccount.php
+++ b/models/MatrixAccount.php
@@ -36,7 +36,9 @@ class MatrixAccount extends SimpleORMap
     public function getLinkedAccount()
     {
         $account = new \Patrix\Account($this->matrix_account_id, $this->matrix_password);
-        MatrixClient::get()->login($account);
+        if (Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) {
+            MatrixClient::get()->login($account);
+        }
         return $account;
     }
 
diff --git a/models/MatrixClient.php b/models/MatrixClient.php
index 881d8653253d27d56d242cd094ae06da151a3f0e..e0ceee4a8bca4587b0becc621a5e2dc5e32bb234 100644
--- a/models/MatrixClient.php
+++ b/models/MatrixClient.php
@@ -30,8 +30,7 @@ class MatrixClient
     {
         if (is_null(MatrixClient::$client)) {
             MatrixClient::$client = new Patrix\MatrixClient(
-                Config::get()->MATRIX_SERVER_HOSTNAME,
-                'https://' . Config::get()->MATRIX_SERVER_HOSTNAME
+                Config::get()->MATRIX_SERVER_HOSTNAME
             );
         }
 
diff --git a/models/MatrixRoom.php b/models/MatrixRoom.php
index 6d5489cfad262ab38a104c5768574bfce1fa070d..4df890f5c3307899c4e4d93e5948dd0c7af1ea93 100644
--- a/models/MatrixRoom.php
+++ b/models/MatrixRoom.php
@@ -158,4 +158,32 @@ class MatrixRoom extends SimpleORMap
         }
     }
 
+    public function requireInvitation($account)
+    {
+        $sysaccount = MatrixAccount::requireSystemAccount();
+
+        $invited = MatrixClient::get()->inviteIntoRoom($sysaccount, $this->getLinkedRoom(), $account->getUserName());
+
+        if ($invited) {
+
+            if ($GLOBALS['perm']->have_studip_perm('dozent', $this->range_id)) {
+                $perm = self::POWER_LEVEL_DOZENT;
+            } else if ($GLOBALS['perm']->have_studip_perm('tutor', $this->range_id)) {
+                $perm = self::POWER_LEVEL_TUTOR;
+            } else {
+                $perm = self::POWER_LEVEL_AUTOR;
+            }
+
+            // Get existing room permissions so that they are not completely overwritten when adding the current user.
+            $permissions = MatrixClient::get()
+                ->getRoomPermissionLevels($sysaccount, $this->getLinkedRoom())
+                ->getUserPermissions();
+
+            $permissions[$account->getUserName()] = $perm;
+
+            // Set correct permission for current user.
+            MatrixClient::get()->setRoomUserPermissionLevels($sysaccount, $this->getLinkedRoom(), $permissions);
+        }
+    }
+
 }
\ No newline at end of file
diff --git a/plugin.manifest b/plugin.manifest
index 9e7879d255a41f772ddc3be978afe960beb077bf..0d884a3dbed8c7062e4a5e36153ece2e12bdba6a 100644
--- a/plugin.manifest
+++ b/plugin.manifest
@@ -1,7 +1,7 @@
 pluginname=Matrix-Chat
 pluginclassname=MatrixPlugin
 origin=data-quest
-version=0.9
+version=0.95
 screenshot=assets/images/matrix_logo.png
 description=Matrix chat for Stud.IP courses
 studipMinVersion=4.5
diff --git a/views/matrix_chat/index.php b/views/matrix_chat/index.php
index c633d59e23dc42a14a878cee44651c16769de2c3..f074c064922872c22e7dc7833dc937af85a828a2 100644
--- a/views/matrix_chat/index.php
+++ b/views/matrix_chat/index.php
@@ -1,4 +1,4 @@
-<? if (!$account) : ?>
+<? if (!$account && Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) : ?>
     <form class="default" action="<?= $controller->link_for('matrix_chat/create_account') ?>" method="post">
         <? if ($no_account_wanted) : ?>
             <?= MessageBox::info(dgettext('matrix',