diff --git a/include/login.inc.php b/include/login.inc.php
new file mode 100644
index 0000000..9566cf2
--- /dev/null
+++ b/include/login.inc.php
@@ -0,0 +1,70 @@
+set_prefilter('identification', 'crypto_login_prefilter');
+ } catch (Throwable $t) {
+ file_put_contents(CRYPTO_PATH . 'debug.log', date('Y-m-d H:i:s') . " - prefilter error: {$t->getMessage()}\n", FILE_APPEND);
+ }
+}
+
+function crypto_login_prefilter($content)
+{
+ // Simply wrap {$CRYPTO.parsed_content} in a Bootstrap Darkroom container
+ $captcha_block = <<
+
+ {\$CRYPTO.parsed_content}
+
+
+HTML;
+
+ $search = '#(]*type="submit"[^>]*>)#i';
+ $replace = $captcha_block . "\n$1";
+
+ $new = @preg_replace($search, $replace, $content, 1);
+ return $new === null ? $content : $new;
+}
+
+/********************************************************************
+ * 2. Block login completely if CAPTCHA fails
+ ********************************************************************/
+add_event_handler('try_log_user', 'crypto_login_block_login', EVENT_HANDLER_PRIORITY_NEUTRAL, 4);
+
+function crypto_login_block_login($success, $username, $password, $remember_me)
+{
+ global $conf, $page;
+
+ if (empty($conf['cryptographp']['activate_on']['login'])) {
+ return $success;
+ }
+
+ include_once(CRYPTO_PATH . 'securimage/securimage.php');
+ $securimage = new Securimage();
+
+ $captcha_ok = !empty($_POST['captcha_code']) && $securimage->check($_POST['captcha_code']);
+
+ if (!$captcha_ok) {
+ $page['errors'][] = l10n('Invalid Captcha');
+ if (isset($_SESSION)) {
+ unset($_SESSION['pwg_uid'], $_SESSION['pwg_username'], $_SESSION['pwg_groups'], $_SESSION['connected_with']);
+ }
+ if (!empty($_COOKIE[session_name()])) {
+ setcookie(session_name(), '', time() - 3600, '/');
+ }
+ return false;
+ }
+
+ return $success;
+}