Skip to content

Commit 8acafa3

Browse files
committed
Honeypot
1 parent 14e5e74 commit 8acafa3

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/Controllers/User/Register.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,21 @@ protected function tryRegister(): void
5555
return;
5656
}
5757

58+
if (!is_null($this->model->active_user))
59+
{
60+
$this->model->error = RegisterModel::ERROR_ALREADY_LOGGED_IN;
61+
return;
62+
}
63+
5864
$q = Router::query();
5965
$this->model->email = $q['email'] ?? null;
6066
$this->model->username = $q['username'] ?? null;
6167

62-
if (!is_null($this->model->active_user))
68+
$this->model->honeypot = $q['confirm_email'] ?? null;
69+
if (is_string($this->model->honeypot) && strlen($this->model->honeypot) > 0)
6370
{
64-
$this->model->error = RegisterModel::ERROR_ALREADY_LOGGED_IN;
71+
// This field should never be filled unless it was a bot.
72+
$this->model->error = RegisterModel::ERROR_REGISTER_DISABLED;
6573
return;
6674
}
6775

src/Models/User/Register.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Register extends \BNETDocs\Models\ActiveUser implements \JsonSerializable
2424

2525
public ?string $denylist_reason = null;
2626
public ?string $email = null;
27+
public ?string $honeypot = null;
2728
public ?\BNETDocs\Libraries\Core\Recaptcha $recaptcha = null;
2829
public ?string $username = null;
2930
public int $username_max_len = 0;
@@ -33,6 +34,7 @@ public function jsonSerialize(): mixed
3334
return \array_merge(parent::jsonSerialize(), [
3435
'denylist_reason' => $this->denylist_reason,
3536
'email' => $this->email,
37+
'honeypot' => $this->honeypot,
3638
'recaptcha' => $this->recaptcha,
3739
'username' => $this->username,
3840
'username_max_len' => $this->username_max_len,

src/Templates/User/Register.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ $email = filter_var($this->getContext()->email, FILTER_SANITIZE_FULL_SPECIAL_CHA
3434
$username = filter_var($this->getContext()->username, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
3535
require('./Includes/header.inc.phtml'); ?>
3636
<div class="container">
37-
<script async defer="defer" src="https://www.google.com/recaptcha/api.js"><![CDATA[]]></script>
37+
<script async defer="defer" src="https://www.google.com/recaptcha/api.js"></script>
3838
<div class="card mx-auto mb-3" style="width:22rem;">
3939
<h3 class="card-header text-center<?=($register_disabled ? ' text-danger' : '')?>"><?=$title?></h3>
4040
<div class="card-body">
@@ -49,6 +49,7 @@ require('./Includes/header.inc.phtml'); ?>
4949
<div class="form-group">
5050
<label class="font-weight-bold" for="email">Email address:</label>
5151
<input class="bg-dark border border-primary form-control text-light" type="email" name="email" id="email" placeholder="Enter the email address here" tabindex="1" value="<?=$email?>" required<?=($af == 'email' ? ' autofocus="autofocus"' : '')?>/>
52+
<input type="text" name="confirm_email" style="display:none;"/>
5253
</div><div class="form-group">
5354
<label class="font-weight-bold" for="username">Username:</label>
5455
<input class="bg-dark border border-primary form-control text-light" type="text" name="username" id="username" placeholder="Enter the username here" tabindex="2" maxlength="<?=$this->getContext()->username_max_len?>" value="<?=$username?>" required<?=($af == 'email' ? ' autofocus="autofocus"' : '')?>/>

0 commit comments

Comments
 (0)