You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/turnstile/tutorials/login-pages.mdx
+32-23Lines changed: 32 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
title: Protect your login pages
2
+
title: Protect your forms
3
3
pcx_content_type: tutorial
4
-
updated: 2024-07-09
4
+
updated: 2025-05-30
5
5
difficulty: Beginner
6
6
languages:
7
7
- JavaScript
@@ -12,12 +12,12 @@ sidebar:
12
12
13
13
---
14
14
15
-
This tutorial will guide you through integrating Cloudflare Turnstile to protect your login page. Learn how to implement the Turnstile widget on the client side and verify the Turnstile token via the siteverify API on the server side.
15
+
This tutorial will guide you through integrating Cloudflare Turnstile to protect your web forms, such as login, signup, or contact forms. Learn how to implement the Turnstile widget on the client side and verify the Turnstile token via the siteverify API on the server side.
16
16
17
17
## Before you begin
18
18
19
19
- You must have a Cloudflare account.
20
-
- You must have a web application with a login or signup page.
20
+
- You must have a web application with a form you want to protect.
21
21
- You must have basic knowledge of HTML and your server-side language of choice, such as Node.js or Python.
22
22
23
23
## Get Your Turnstile sitekey and secret key
@@ -28,26 +28,34 @@ This tutorial will guide you through integrating Cloudflare Turnstile to protect
28
28
29
29
## Add the Turnstile widget to your HTML form
30
30
31
-
1. Add the Turnstile widget to your login form.
31
+
1. Add the Turnstile widget to your form.
32
32
2. Replace `YOUR-SITE-KEY` with the sitekey from Cloudflare.
33
+
3. Add a `data-callback` attribute to the Turnstile widget div. This JavaScript function will be called when the challenge is successful.
34
+
4. Ensure your submit button is initially disabled.
It is crucial to handle the verification of the Turnstile token correctly. This section covers some key points to keep in mind.
102
111
103
-
### Verify the token after credentials input
112
+
### Verify the token after form input
104
113
105
-
- Ensure that you verify the Turnstile token after the user has put in their credentials and selected **log in** to your website or application.
106
-
- If you verify the token before the user inputs their credentials, a malicious visitor could bypass the protection by reentering the login credentials.
114
+
- Ensure that you verify the Turnstile token after the user has filled out the form and selected **submit**.
115
+
- If you verify the token before the user inputs their data, a malicious actor could potentially bypass the protection by manipulating the form submission after obtaining a valid token.
107
116
108
117
### Proper flow implementation
109
118
110
-
- When the user submits the login form, send both the login credentials and the Turnstile token to your server.
119
+
- When the user submits the form, send both the form data and the Turnstile token to your server.
111
120
- On the server side, verify the Turnstile token first.
112
-
- Based on the verification response, decide whether to proceed with checking the login credentials.
121
+
- Based on the verification response, decide whether to proceed with processing the form data.
0 commit comments