Skip to content

Commit 66f5d2b

Browse files
committed
add fake email field to register page to catch spammers
1 parent b686e33 commit 66f5d2b

3 files changed

Lines changed: 40 additions & 3 deletions

File tree

‎controllers/RegisterController.php‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,27 @@ public function register(
6666
$username = (string) $post['username'] ?? '';
6767
$password = (string) $post['password'] ?? '';
6868
$repeat_password = (string) $post['repeat_password'] ?? '';
69-
$email = (string) $post['email'] ?? '';
69+
$email = (string) $post['_x_email'] ?? ''; // _x_email = real email input
70+
71+
// Get fake email POST var
72+
// This is meant to catch spam bots
73+
$fake_email = (string) $post['email'] ?? ''; // 'email' = fake email input
74+
if(!empty($fake_email))
75+
{
76+
// Make the bot waste some extra time
77+
// Sleep between 0.4 and 1.2 seconds
78+
\usleep(\mt_rand(400, 1200) * 1000);
79+
80+
// Show a warning
81+
$flash->warning('Invalid email address.');
82+
83+
// Render register page
84+
$response->getBody()->write(
85+
$twig->render('register.html.twig')
86+
);
87+
88+
return $response;
89+
}
7090

7191
// Success will be false if anything fails
7292
// This way we can show multiple warnings

‎public/css/theme.css‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,4 +1468,14 @@ div.emoji-drop-down div.emoji {
14681468

14691469
/*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
14701470
/*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
1471-
/*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
1471+
/*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
1472+
1473+
/* Hide the fake email field on the register page to catch spam bots */
1474+
/* #catch_them {
1475+
margin: 0;
1476+
width: 0;
1477+
height: 0;
1478+
position: relative;
1479+
top: -9999px;
1480+
left: -999999px;
1481+
} */

‎views/register.html.twig‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,17 @@
4646
<input type="text" class="form-control" id="username" name="username" value="{{ get_post_var('username') }}" required>
4747
</div>
4848

49-
<div class="form-group">
49+
{# This input is meant to catch spammers and block them #}
50+
<div class="form-group" id="catch_them">
5051
<label for="email">Email address <span class="text-muted">(Optional)</span></label>
5152
<input type="email" class="form-control" id="email" name="email" value="{{ get_post_var('email') }}">
5253
</div>
5354

55+
<div class="form-group">
56+
<label for="_x_email">Email address <span class="text-muted">(Optional)</span></label>
57+
<input type="email" class="form-control" id="_x_email" name="_x_email" value="{{ get_post_var('_x_email') }}">
58+
</div>
59+
5460
<div class="form-group">
5561
<label for="password">Password</label>
5662
<input type="password" class="form-control" id="password" name="password" value="" required>
@@ -100,3 +106,4 @@
100106
});
101107
</script>
102108
{% endblock %}
109+

0 commit comments

Comments
 (0)